Throw sensible error if user without port assignment logs on

This commit is contained in:
Daniel Schick 2024-12-06 11:40:00 +01:00
parent 2df14d957b
commit e28a5c1560
4 changed files with 54 additions and 21 deletions

View File

@ -169,14 +169,24 @@ namespace BreCalClient
if (_loginResult.Id > 0)
{
Mouse.OverrideCursor = Cursors.Wait;
this.busyIndicator.IsBusy = false;
this._userApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._shipcallApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._timesApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._staticApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._shipApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this.LoadStaticLists();
this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}";
bool loadingSuccessful = await this.LoadStaticLists();
if (loadingSuccessful)
{
this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}";
this.busyIndicator.IsBusy = false;
}
else
{
Mouse.OverrideCursor = null;
textUsername.Text = "";
textPassword.Password = "";
textUsername.Focus();
}
}
}
labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}";
@ -428,15 +438,22 @@ namespace BreCalClient
#region network operations
private async void LoadStaticLists()
private async Task<bool> LoadStaticLists()
{
if (_loginResult == null) return;
if (_loginResult == null) return false;
BreCalLists.InitializePorts(await _staticApi.GetPortsAsync());
BreCalLists.InitializeBerths(await _staticApi.BerthsGetAsync());
BreCalLists.InitializeShips(await _shipApi.ShipsGetAsync());
BreCalLists.InitializeParticipants(await _staticApi.ParticipantsGetAsync());
if(BreCalLists.Participants.Count == 0)
{
MessageBox.Show(BreCalClient.Resources.Resources.textNoPortAssigned, BreCalClient.Resources.Resources.textError, MessageBoxButton.OK, MessageBoxImage.Error);
Mouse.OverrideCursor = Cursors.Wait;
return false;
}
this.searchFilterControl.SetBerths(BreCalLists.Berths);
foreach (Participant participant in BreCalLists.Participants)
@ -473,7 +490,7 @@ namespace BreCalClient
}
this.searchFilterControl.SetFilterFromModel(currentFilter);
if (currentFilter.Ports != null)
if ((currentFilter.Ports != null) && (this.comboBoxPorts.ItemsSource != null))
{
foreach (Port p in this.comboBoxPorts.ItemsSource)
{
@ -485,6 +502,7 @@ namespace BreCalClient
_ = Task.Run(() => RefreshShipcalls());
_ = Task.Run(() => RefreshShips());
return true;
}

View File

@ -875,6 +875,15 @@ namespace BreCalClient.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No port assigned to this participant.
/// </summary>
public static string textNoPortAssigned {
get {
return ResourceManager.GetString("textNoPortAssigned", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Not rotated.
/// </summary>

View File

@ -553,4 +553,7 @@
<data name="textStartTimeMissing" xml:space="preserve">
<value>Wenn eine Ende-Zeit angegeben wird, muss auch eine Start-Zeit angegeben werden</value>
</data>
<data name="textNoPortAssigned" xml:space="preserve">
<value>Es ist keine Hafenzuordnung vorhanden</value>
</data>
</root>

View File

@ -601,4 +601,7 @@
<data name="textStartTimeMissing" xml:space="preserve">
<value>If an end time is set, a start time is also required</value>
</data>
<data name="textNoPortAssigned" xml:space="preserve">
<value>No port assigned to this participant</value>
</data>
</root>