Save and display a new shipcall
This commit is contained in:
parent
95fab27229
commit
ee5420ff5b
@ -31,6 +31,13 @@ namespace BreCalClient
|
||||
|
||||
public List<Ship> Ships { get; set; } = new();
|
||||
|
||||
public Ship? SelectedShip {
|
||||
get
|
||||
{
|
||||
return this.comboBoxShip.SelectedItem as Ship;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handler
|
||||
|
||||
@ -88,9 +88,9 @@ namespace BreCalClient
|
||||
try
|
||||
{
|
||||
_loginResult = await _api.LoginPostAsync(credentials);
|
||||
if(_loginResult != null)
|
||||
if (_loginResult != null)
|
||||
{
|
||||
if(_loginResult.Id > 0)
|
||||
if (_loginResult.Id > 0)
|
||||
{
|
||||
this.busyIndicator.IsBusy = false;
|
||||
this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token;
|
||||
@ -105,7 +105,7 @@ namespace BreCalClient
|
||||
this.labelLoginResult.Content = ex.Message;
|
||||
labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}";
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}";
|
||||
@ -128,10 +128,9 @@ namespace BreCalClient
|
||||
|
||||
if (esc.ShowDialog() ?? false)
|
||||
{
|
||||
// save new dialog model
|
||||
|
||||
// add dialog model to list
|
||||
|
||||
// create UI & save new dialog model
|
||||
this.UpdateShipcallUI(esc.Shipcall);
|
||||
this._api.ShipcallsPost(esc.Shipcall);
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,6 +229,32 @@ namespace BreCalClient
|
||||
if (shipcalls != null)
|
||||
{
|
||||
foreach (Shipcall shipcall in shipcalls)
|
||||
{
|
||||
this.UpdateShipcallUI(shipcall);
|
||||
}
|
||||
|
||||
List<ShipcallControl> removeList = new();
|
||||
foreach (ShipcallControlModel scm in this._controlModels)
|
||||
{
|
||||
if (shipcalls.Find(s => s.Id == scm.Shipcall?.Id) == null) // the model is no longer in the search result
|
||||
{
|
||||
if((scm.Shipcall != null) && this._shipCallControlDict.ContainsKey(scm.Shipcall.Id))
|
||||
{
|
||||
this.Dispatcher.Invoke((Action)(() =>
|
||||
{
|
||||
this.stackPanel.Children.Remove(this._shipCallControlDict[scm.Shipcall.Id]);
|
||||
}));
|
||||
this._shipCallControlDict.Remove(scm.Shipcall.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(SHIPCALL_UPDATE_INTERVAL_SECONDS), _tokenSource.Token);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateShipcallUI(Shipcall shipcall)
|
||||
{
|
||||
ShipcallControlModel? selectedSCMModel = null;
|
||||
|
||||
@ -278,28 +303,6 @@ namespace BreCalClient
|
||||
{
|
||||
this._shipCallControlDict[shipcall.Id].RefreshData();
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
List<ShipcallControl> removeList = new();
|
||||
foreach (ShipcallControlModel scm in this._controlModels)
|
||||
{
|
||||
if (shipcalls.Find(s => s.Id == scm.Shipcall?.Id) == null) // the model is no longer in the search result
|
||||
{
|
||||
if((scm.Shipcall != null) && this._shipCallControlDict.ContainsKey(scm.Shipcall.Id))
|
||||
{
|
||||
this.Dispatcher.Invoke((Action)(() =>
|
||||
{
|
||||
this.stackPanel.Children.Remove(this._shipCallControlDict[scm.Shipcall.Id]);
|
||||
}));
|
||||
this._shipCallControlDict.Remove(scm.Shipcall.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(SHIPCALL_UPDATE_INTERVAL_SECONDS), _tokenSource.Token);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Sc_EditRequested(ShipcallControl obj)
|
||||
|
||||
Reference in New Issue
Block a user