Diverse Meldungen
This commit is contained in:
@@ -45,6 +45,21 @@ class Auth {
|
|||||||
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) }) {
|
||||||
|
|
||||||
|
//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
|
//Gemeinde ist ein Pflichtfeld
|
||||||
if (item.GemeindeAktiv == null) {
|
if (item.GemeindeAktiv == null) {
|
||||||
throw new Exception("Gemeinde nicht gewählt");
|
throw new Exception("Gemeinde nicht gewählt");
|
||||||
@@ -53,7 +68,11 @@ class Auth {
|
|||||||
if (item.ProjektAktiv == null) {
|
if (item.ProjektAktiv == null) {
|
||||||
throw new Exception("Projekt nicht gewählt");
|
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();
|
HttpClient client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
@@ -67,29 +86,34 @@ class Auth {
|
|||||||
else
|
else
|
||||||
response = await client.PutAsync(url, content);
|
response = await client.PutAsync(url, content);
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
//if (response.IsSuccessStatusCode)
|
||||||
Debug.WriteLine(@"\tTodoItem successfully saved.");
|
// Debug.WriteLine(@"\tTodoItem successfully saved.");
|
||||||
} catch (Exception ex) {
|
if (!response.IsSuccessStatusCode) {
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
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) {
|
public static async Task DeleteItemAsync(string url, string token) {
|
||||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||||
|
|
||||||
try {
|
//try {
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||||
|
|
||||||
HttpResponseMessage response = await client.DeleteAsync(url);
|
HttpResponseMessage response = await client.DeleteAsync(url);
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
Debug.WriteLine(@"\tTodoItem successfully deleted.");
|
throw new Exception("Fehler beim Löschen " + response.Content);
|
||||||
} catch (Exception ex) {
|
//if (response.IsSuccessStatusCode)
|
||||||
Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
// Debug.WriteLine(@"\tTodoItem successfully deleted.");
|
||||||
}
|
//} catch (Exception ex) {
|
||||||
|
// Debug.WriteLine(@"\tERROR {0}", ex.Message);
|
||||||
|
//}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user