fixed some cut and paste error and a crash when changing the assignment fails by API

This commit is contained in:
Daniel Schick 2024-09-11 08:41:49 +02:00
parent 282a860c42
commit e7a6aa6584
5 changed files with 41 additions and 11 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

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

View File

@ -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<Extensions.ParticipantType, ParticipantAssignment> AssignedParticipants { get; } = new();
public List<Times> Times { get; set; } = new();
@ -247,8 +250,9 @@ namespace BreCalClient
/// This function updates the assignments for existing times records accordingly and saves them.
/// </summary>
/// <param name="_api">API reference to PUT eidted times</param>
internal async void UpdateTimesAssignments(TimesApi api)
internal async Task<bool> UpdateTimesAssignments(TimesApi api)
{
foreach (Extensions.ParticipantType participantType in this.AssignedParticipants.Keys)
{
Times? times = this.GetTimesForParticipantType(participantType);
@ -256,8 +260,16 @@ namespace BreCalClient
if(times.ParticipantId != this.AssignedParticipants[participantType].ParticipantId)
{
times.ParticipantId = this.AssignedParticipants[participantType].ParticipantId;
try
{
await api.TimesUpdateAsync(times);
}
catch (Exception ex)
{
LastErrorMessage = ex.Message;
return false;
}
}
}
// if somebody just removed an assignment it is gone fom AssignedParticipants, but there is still a
@ -282,10 +294,19 @@ namespace BreCalClient
}
foreach(Times times in deleteTimes)
{
try
{
api.TimesDelete(times.Id);
this.Times.Remove(times);
}
catch (Exception ex)
{
LastErrorMessage = ex.Message;
return false;
}
}
return true;
}
#endregion