Fehler beim Webservice abfangen

Und Meldung ausgeben
This commit is contained in:
2024-08-28 10:53:50 +02:00
parent c5879373c6
commit 2aff974144
2 changed files with 19 additions and 2 deletions

View File

@@ -82,12 +82,20 @@ namespace Jugenddienst_Stunden.ViewModels {
//public async Task LoadData() =>
// await Models.Stunde.LoadData();
public event EventHandler<string> AlertEvent;
public async Task LoadData() {
try {
_hour = await Models.Stunde.LoadData();
} catch (Exception e) {
AlertEvent?.Invoke(this, e.Message);
}
//Models.Hours Hours = new Models.Hours();
//Title = _hour.operator_api.name + " " + _hour.operator_api.surname;
if (_hour != null) {
RefreshProperties();
}
}
private void RefreshProperties() {
OnPropertyChanged(nameof(Nominal));

View File

@@ -1,8 +1,17 @@
using Jugenddienst_Stunden.ViewModels;
namespace Jugenddienst_Stunden.Views;
public partial class StundenPage : ContentPage {
public StundenPage() {
InitializeComponent();
if(BindingContext is StundenViewModel vm) {
vm.AlertEvent += Vm_AlertEvent;
}
}
private void Vm_AlertEvent(object? sender, string e) {
DisplayAlert("Fehler:", e, "OK");
}
protected override void OnAppearing() {