Gemeinde und Projekt als Pflichtfeld
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
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;
|
||||||
@@ -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");
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user