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 Ship? SelectedShip {
get
{
return this.comboBoxShip.SelectedItem as Ship;
}
}
#endregion
#region Event handler

View File

@ -82,15 +82,15 @@ namespace BreCalClient
return;
}
Credentials credentials = new(username: textUsername.Text.Trim(),
Credentials credentials = new(username: textUsername.Text.Trim(),
password: textPassword.Password.Trim());
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,12 +128,11 @@ 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);
}
}
private void buttonInfo_Click(object sender, RoutedEventArgs e)
{
@ -231,54 +230,7 @@ namespace BreCalClient
{
foreach (Shipcall shipcall in shipcalls)
{
ShipcallControlModel? selectedSCMModel = null;
foreach (ShipcallControlModel scm in this._controlModels)
{
if (scm.Shipcall?.Id == shipcall.Id)
{
selectedSCMModel = scm;
break;
}
}
if (selectedSCMModel != null)
{
selectedSCMModel.Shipcall = shipcall;
}
else
{
// no: create new entry
selectedSCMModel = new()
{
Shipcall = shipcall
};
if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))
selectedSCMModel.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name;
_controlModels.Add(selectedSCMModel);
this.Dispatcher.Invoke(new Action(() =>
{
ShipcallControl sc = new()
{
Height = 120,
ShipcallControlModel = selectedSCMModel
};
sc.TimesRequested += Sc_TimesRequested;
sc.EditRequested += Sc_EditRequested;
this.stackPanel.Children.Add(sc);
this._shipCallControlDict[shipcall.Id] = sc;
}));
}
selectedSCMModel.AssignParticipants(this._participants);
this.Dispatcher.Invoke((Action)(() =>
{
this._shipCallControlDict[shipcall.Id].RefreshData();
}));
this.UpdateShipcallUI(shipcall);
}
List<ShipcallControl> removeList = new();
@ -302,6 +254,57 @@ namespace BreCalClient
}
}
private void UpdateShipcallUI(Shipcall shipcall)
{
ShipcallControlModel? selectedSCMModel = null;
foreach (ShipcallControlModel scm in this._controlModels)
{
if (scm.Shipcall?.Id == shipcall.Id)
{
selectedSCMModel = scm;
break;
}
}
if (selectedSCMModel != null)
{
selectedSCMModel.Shipcall = shipcall;
}
else
{
// no: create new entry
selectedSCMModel = new()
{
Shipcall = shipcall
};
if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))
selectedSCMModel.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name;
_controlModels.Add(selectedSCMModel);
this.Dispatcher.Invoke(new Action(() =>
{
ShipcallControl sc = new()
{
Height = 120,
ShipcallControlModel = selectedSCMModel
};
sc.TimesRequested += Sc_TimesRequested;
sc.EditRequested += Sc_EditRequested;
this.stackPanel.Children.Add(sc);
this._shipCallControlDict[shipcall.Id] = sc;
}));
}
selectedSCMModel.AssignParticipants(this._participants);
this.Dispatcher.Invoke((Action)(() =>
{
this._shipCallControlDict[shipcall.Id].RefreshData();
}));
}
private async void Sc_EditRequested(ShipcallControl obj)
{
Shipcall? sc = obj.ShipcallControlModel?.Shipcall;