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,6 +2,7 @@
using System.Text;
using Jugenddienst_Stunden.Types;
using System.Text.Json;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Jugenddienst_Stunden.Models;
@@ -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) {
//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");

View File

@@ -104,13 +104,21 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
}
async Task Save() {
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")}");
}
}
}
private async Task Delete() {
await Models.Stunde.DeleteEntry(_stunde);
@@ -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;

View File

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