diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs index 8889dd8..933a230 100644 --- a/src/BreCalClient/EditShipcallControl.xaml.cs +++ b/src/BreCalClient/EditShipcallControl.xaml.cs @@ -31,6 +31,13 @@ namespace BreCalClient public List Ships { get; set; } = new(); + public Ship? SelectedShip { + get + { + return this.comboBoxShip.SelectedItem as Ship; + } + } + #endregion #region Event handler diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 7ce890f..8b86f92 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -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 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;