Diverse Meldungen

This commit is contained in:
2024-10-18 16:24:09 +02:00
parent fe3cefe22b
commit b27e8ffcce

View File

@@ -45,6 +45,21 @@ class Auth {
public static async Task SaveItemAsync(string url, string token, DayTime item, bool isNewItem = false) {
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
//Uhrzeiten sollten sinnvolle Werte haben
if (item.TimeSpanVon == item.TimeSpanBis) {
throw new Exception("Beginn und Ende sind gleich");
}
if (item.TimeSpanBis < item.TimeSpanVon) {
throw new Exception("Ende ist vor Beginn");
}
TimeSpan span = TimeSpan.Zero;
span += item.TimeSpanBis - item.TimeSpanVon;
if (span.Hours > 10) {
//Hier vielleicht eine Abfrage, ob mehr als 10 Stunden gesund sind?
}
//Gemeinde ist ein Pflichtfeld
if (item.GemeindeAktiv == null) {
throw new Exception("Gemeinde nicht gewählt");
@@ -53,7 +68,11 @@ class Auth {
if (item.ProjektAktiv == null) {
throw new Exception("Projekt nicht gewählt");
}
try {
//Keine Beschreibung
if (string.IsNullOrEmpty(item.description)) {
throw new Exception("Keine Beschreibung");
}
//try {
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
@@ -67,29 +86,34 @@ class Auth {
else
response = await client.PutAsync(url, content);
if (response.IsSuccessStatusCode)
Debug.WriteLine(@"\tTodoItem successfully saved.");
} catch (Exception ex) {
Debug.WriteLine(@"\tERROR {0}", ex.Message);
//if (response.IsSuccessStatusCode)
// Debug.WriteLine(@"\tTodoItem successfully saved.");
if (!response.IsSuccessStatusCode) {
throw new Exception("Fehler beim Speichern " + response.Content);
}
//} catch (Exception ex) {
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
//}
//}
}
public static async Task DeleteItemAsync(string url, string token) {
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
try {
//try {
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
HttpResponseMessage response = await client.DeleteAsync(url);
if (response.IsSuccessStatusCode)
Debug.WriteLine(@"\tTodoItem successfully deleted.");
} catch (Exception ex) {
Debug.WriteLine(@"\tERROR {0}", ex.Message);
}
if (!response.IsSuccessStatusCode)
throw new Exception("Fehler beim Löschen " + response.Content);
//if (response.IsSuccessStatusCode)
// Debug.WriteLine(@"\tTodoItem successfully deleted.");
//} catch (Exception ex) {
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
//}
//}
}