Save and display a new shipcall

This commit is contained in:
Daniel Schick 2023-08-21 16:20:12 +02:00
parent 95fab27229
commit ee5420ff5b
2 changed files with 68 additions and 58 deletions

View File

@ -31,6 +31,13 @@ namespace BreCalClient
public List<Ship> Ships { get; set; } = new(); public List<Ship> Ships { get; set; } = new();
public Ship? SelectedShip {
get
{
return this.comboBoxShip.SelectedItem as Ship;
}
}
#endregion #endregion
#region Event handler #region Event handler

View File

@ -88,9 +88,9 @@ namespace BreCalClient
try try
{ {
_loginResult = await _api.LoginPostAsync(credentials); _loginResult = await _api.LoginPostAsync(credentials);
if(_loginResult != null) if (_loginResult != null)
{ {
if(_loginResult.Id > 0) if (_loginResult.Id > 0)
{ {
this.busyIndicator.IsBusy = false; this.busyIndicator.IsBusy = false;
this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token; this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token;
@ -105,7 +105,7 @@ namespace BreCalClient
this.labelLoginResult.Content = ex.Message; this.labelLoginResult.Content = ex.Message;
labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}"; labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}";
} }
catch(Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}"; labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}";
@ -128,10 +128,9 @@ namespace BreCalClient
if (esc.ShowDialog() ?? false) if (esc.ShowDialog() ?? false)
{ {
// save new dialog model // create UI & save new dialog model
this.UpdateShipcallUI(esc.Shipcall);
// add dialog model to list this._api.ShipcallsPost(esc.Shipcall);
} }
} }
@ -230,6 +229,32 @@ namespace BreCalClient
if (shipcalls != null) if (shipcalls != null)
{ {
foreach (Shipcall shipcall in shipcalls) 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; ShipcallControlModel? selectedSCMModel = null;
@ -278,28 +303,6 @@ namespace BreCalClient
{ {
this._shipCallControlDict[shipcall.Id].RefreshData(); 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) private async void Sc_EditRequested(ShipcallControl obj)