Gemeinde und Projekt als Pflichtfeld

This commit is contained in:
2024-10-12 18:23:00 +02:00
parent caebc63e42
commit ac1941b134
3 changed files with 34 additions and 8 deletions

View File

@@ -2,9 +2,10 @@
using System.Text; using System.Text;
using Jugenddienst_Stunden.Types; using Jugenddienst_Stunden.Types;
using System.Text.Json; using System.Text.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Jugenddienst_Stunden.Models; namespace Jugenddienst_Stunden.Models;
class Auth { class Auth {
public static async Task<string> GetApiDataWithAuthAsync(string url, string token) { public static async Task<string> GetApiDataWithAuthAsync(string url, string token) {
@@ -34,9 +35,25 @@ class Auth {
} }
/// <summary>
/// Stundeneintrag speichern
/// </summary>
/// <param name="url"></param>
/// <param name="token"></param>
/// <param name="item"></param>
/// <param name="isNewItem"></param>
/// <returns></returns>
public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) { public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) { //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 { try {
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json"); client.DefaultRequestHeaders.Add("Accept", "application/json");

View File

@@ -104,11 +104,19 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
} }
async Task Save() { async Task Save() {
await Models.Stunde.SaveEntry(_stunde); bool exceptionOccurred = false;
if (_stunde.id != null) { try {
await Shell.Current.GoToAsync($"..?saved={_stunde.id}"); await Models.Stunde.SaveEntry(_stunde);
} else { } catch (Exception e) {
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}"); 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 { try {
DayTimes = await Models.Stunde.LoadDay(_date); DayTimes = await Models.Stunde.LoadDay(_date);
} catch (Exception) { } 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; _stunde.day = _date;

View File

@@ -10,7 +10,7 @@ public partial class StundePage : ContentPage {
InitializeComponent(); InitializeComponent();
if (BindingContext is StundeViewModel vm) { if (BindingContext is StundeViewModel vm) {
//vm.AlertEvent += Vm_AlertEvent; vm.AlertEvent += Vm_AlertEvent;
//vm.InfoEvent += Vm_InfoEvent; //vm.InfoEvent += Vm_InfoEvent;
vm.ConfirmEvent += ShowConfirm; vm.ConfirmEvent += ShowConfirm;
} }