From e7a6aa65844746e9f5bfb806f46d06977208cc13 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 11 Sep 2024 08:41:49 +0200 Subject: [PATCH] fixed some cut and paste error and a crash when changing the assignment fails by API --- .../EditTimesAgencyIncomingControl.xaml.cs | 2 +- .../EditTimesAgencyOutgoingControl.xaml.cs | 2 +- .../EditTimesAgencyShiftingControl.xaml.cs | 4 +-- src/BreCalClient/MainWindow.xaml.cs | 13 ++++++-- src/BreCalClient/ShipcallControlModel.cs | 31 ++++++++++++++++--- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs index e7c2bb7..b1eba3b 100644 --- a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs @@ -105,7 +105,7 @@ namespace BreCalClient if(this.datePickerETA_End.Value.HasValue && this.datePickerETA_End.Value < DateTime.Now) { - message = BreCalClient.Resources.Resources.textETDInThePast; + message = BreCalClient.Resources.Resources.textETAInThePast; return false; } diff --git a/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs index 17dc94b..7258006 100644 --- a/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs @@ -109,7 +109,7 @@ namespace BreCalClient if (this.datePickerETD.Value.HasValue && (this.datePickerETD.Value.Value < DateTime.Now) && (this.datePickerETD_End.Value == null)) { - message = BreCalClient.Resources.Resources.textETAInThePast; + message = BreCalClient.Resources.Resources.textETDInThePast; return false; } diff --git a/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs b/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs index f0cf0e9..e8398ce 100644 --- a/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs +++ b/src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs @@ -105,7 +105,7 @@ namespace BreCalClient if (this.datePickerETA_End.Value.HasValue && this.datePickerETA_End.Value < DateTime.Now) { - message = BreCalClient.Resources.Resources.textETDInThePast; + message = BreCalClient.Resources.Resources.textETAInThePast; return false; } @@ -117,7 +117,7 @@ namespace BreCalClient if (this.datePickerETD.Value.HasValue && (this.datePickerETD.Value.Value < DateTime.Now) && (this.datePickerETD_End.Value == null)) { - message = BreCalClient.Resources.Resources.textETAInThePast; + message = BreCalClient.Resources.Resources.textETDInThePast; return false; } diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index bbcd559..db705dd 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -899,7 +899,10 @@ namespace BreCalClient try { obj.ShipcallControlModel.Shipcall?.Participants.Clear(); - obj.ShipcallControlModel.UpdateTimesAssignments(this._timesApi); + if(! await obj.ShipcallControlModel.UpdateTimesAssignments(this._timesApi)) + { + ShowErrorDialog(obj.ShipcallControlModel.LastErrorMessage, "Update assignments error"); + } foreach(ParticipantAssignment pa in obj.ShipcallControlModel.AssignedParticipants.Values) obj.ShipcallControlModel.Shipcall?.Participants.Add(pa); await _shipcallApi.ShipcallUpdateAsync(obj.ShipcallControlModel.Shipcall); @@ -1011,7 +1014,13 @@ namespace BreCalClient { try { - sc.ShipcallControlModel?.UpdateTimesAssignments(_timesApi); // if the agent changed the assignment of the participant to another + if (sc.ShipcallControlModel != null) + { + if (!await sc.ShipcallControlModel.UpdateTimesAssignments(_timesApi)) // if the agent changed the assignment of the participant to another + { + ShowErrorDialog(sc.ShipcallControlModel.LastErrorMessage, "Error updating times assignment"); + } + } // always try to be the agent, even if we are BSMD if (editControl.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY)) diff --git a/src/BreCalClient/ShipcallControlModel.cs b/src/BreCalClient/ShipcallControlModel.cs index cf112c5..7cc91d6 100644 --- a/src/BreCalClient/ShipcallControlModel.cs +++ b/src/BreCalClient/ShipcallControlModel.cs @@ -6,6 +6,7 @@ using BreCalClient.misc.Api; using BreCalClient.misc.Model; using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace BreCalClient { @@ -38,6 +39,8 @@ namespace BreCalClient public string? Berth { get; set; } + public string LastErrorMessage { get; private set; } = ""; + internal Dictionary AssignedParticipants { get; } = new(); public List Times { get; set; } = new(); @@ -247,8 +250,9 @@ namespace BreCalClient /// This function updates the assignments for existing times records accordingly and saves them. /// /// API reference to PUT eidted times - internal async void UpdateTimesAssignments(TimesApi api) - { + internal async Task UpdateTimesAssignments(TimesApi api) + { + foreach (Extensions.ParticipantType participantType in this.AssignedParticipants.Keys) { Times? times = this.GetTimesForParticipantType(participantType); @@ -256,7 +260,15 @@ namespace BreCalClient if(times.ParticipantId != this.AssignedParticipants[participantType].ParticipantId) { times.ParticipantId = this.AssignedParticipants[participantType].ParticipantId; - await api.TimesUpdateAsync(times); + try + { + await api.TimesUpdateAsync(times); + } + catch (Exception ex) + { + LastErrorMessage = ex.Message; + return false; + } } } @@ -283,9 +295,18 @@ namespace BreCalClient foreach(Times times in deleteTimes) { - api.TimesDelete(times.Id); - this.Times.Remove(times); + try + { + api.TimesDelete(times.Id); + this.Times.Remove(times); + } + catch (Exception ex) + { + LastErrorMessage = ex.Message; + return false; + } } + return true; } #endregion