diff --git a/Jugenddienst Stunden/Models/Auth.cs b/Jugenddienst Stunden/Models/Auth.cs index 19278c0..8e2d295 100644 --- a/Jugenddienst Stunden/Models/Auth.cs +++ b/Jugenddienst Stunden/Models/Auth.cs @@ -2,9 +2,10 @@ using System.Text; using Jugenddienst_Stunden.Types; using System.Text.Json; +using static System.Runtime.InteropServices.JavaScript.JSType; -namespace Jugenddienst_Stunden.Models; +namespace Jugenddienst_Stunden.Models; class Auth { public static async Task GetApiDataWithAuthAsync(string url, string token) { @@ -34,9 +35,25 @@ class Auth { } + /// + /// Stundeneintrag speichern + /// + /// + /// + /// + /// + /// public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) { //using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) { + //Gemeinde ist ein Pflichtfeld + if (item.GemeindeAktiv == null) { + throw new Exception("Gemeinde nicht gewählt"); + } + //Projekt ist ein Pflichtfeld + if (item.ProjektAktiv == null) { + throw new Exception("Projekt nicht gewählt"); + } try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Accept", "application/json"); diff --git a/Jugenddienst Stunden/ViewModels/StundeViewModel.cs b/Jugenddienst Stunden/ViewModels/StundeViewModel.cs index c244b46..0c42213 100644 --- a/Jugenddienst Stunden/ViewModels/StundeViewModel.cs +++ b/Jugenddienst Stunden/ViewModels/StundeViewModel.cs @@ -104,11 +104,19 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable { } async Task Save() { - await Models.Stunde.SaveEntry(_stunde); - if (_stunde.id != null) { - await Shell.Current.GoToAsync($"..?saved={_stunde.id}"); - } else { - await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}"); + bool exceptionOccurred = false; + try { + await Models.Stunde.SaveEntry(_stunde); + } catch (Exception e) { + AlertEvent?.Invoke(this, e.Message); + exceptionOccurred = true; + } + if (!exceptionOccurred) { + if (_stunde.id != null) { + await Shell.Current.GoToAsync($"..?saved={_stunde.id}"); + } else { + await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}"); + } } } @@ -175,7 +183,8 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable { try { DayTimes = await Models.Stunde.LoadDay(_date); } catch (Exception) { - //Ein Tag ohne Einträge gibt eine Fehlermeldung, die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht + //Ein Tag ohne Einträge gibt eine Fehlermeldung, + //die soll aber ignoriert werden, weil beim Neueintrag ist das ja Wurscht } _stunde.day = _date; diff --git a/Jugenddienst Stunden/Views/StundePage.xaml.cs b/Jugenddienst Stunden/Views/StundePage.xaml.cs index 9a30d65..303ede5 100644 --- a/Jugenddienst Stunden/Views/StundePage.xaml.cs +++ b/Jugenddienst Stunden/Views/StundePage.xaml.cs @@ -10,7 +10,7 @@ public partial class StundePage : ContentPage { InitializeComponent(); if (BindingContext is StundeViewModel vm) { - //vm.AlertEvent += Vm_AlertEvent; + vm.AlertEvent += Vm_AlertEvent; //vm.InfoEvent += Vm_InfoEvent; vm.ConfirmEvent += ShowConfirm; }