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

@ -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)