Save / Update / Delete Entrys
This commit is contained in:
@@ -70,6 +70,24 @@ namespace Jugenddienst_Stunden.Models {
|
||||
//}
|
||||
}
|
||||
|
||||
public static async Task DeleteItemAsync(string url, string token) {
|
||||
//using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) {
|
||||
|
||||
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);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,9 @@ namespace Jugenddienst_Stunden.Models {
|
||||
|
||||
//Christine Feichter
|
||||
public static string apiKey = Preferences.Default.Get("apiKey", "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
public static string name = Preferences.Default.Get("name", "Christine");
|
||||
public static string surname = Preferences.Default.Get("surname", "Feichter");
|
||||
public static int EmployeeId = Preferences.Default.Get("employeeId", 0);
|
||||
public static string name = Preferences.Default.Get("name", "Vorname");
|
||||
public static string surname = Preferences.Default.Get("surname", "Nachname");
|
||||
public static string apiUrl = Preferences.Default.Get("apiUrl", "https://");
|
||||
|
||||
//Damian
|
||||
@@ -71,6 +72,32 @@ namespace Jugenddienst_Stunden.Models {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public static async Task<Hours> LoadBasicData() {
|
||||
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?basic", tokendata.apiKey);
|
||||
|
||||
if (data == "null") {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
public static async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||
|
||||
@@ -134,7 +161,18 @@ namespace Jugenddienst_Stunden.Models {
|
||||
public static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
await Auth.SaveItemAsync(tokendata.url, tokendata.apiKey, stunde,false);
|
||||
bool isNew = false;
|
||||
if (stunde.id == null)
|
||||
isNew = true;
|
||||
await Auth.SaveItemAsync(tokendata.url, tokendata.apiKey, stunde, isNew);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
|
||||
public static async Task<DayTime> DeleteEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
await Auth.DeleteItemAsync(tokendata.url + "/entry/" + stunde.id, tokendata.apiKey);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user