Files
Jugenddienst-Stunden/Jugenddienst Stunden/Models/Stunde.cs
2024-08-21 00:11:59 +02:00

55 lines
1.6 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using Microsoft.Maui.Networking;
using Microsoft.Maui.Controls;
using System;
using System.Text;
namespace Jugenddienst_Stunden.Models {
internal class Stunde : ObservableObject {
//Katharina
public static string apiKey = Preferences.Default.Get("apiKey", "MTAyfEJZZnB1L3VwcnhoVms0dDlLZENPZWtUVy85b3xodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
//Damian
//public static string apiKey = Preferences.Default.Get("apiKey", "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
//private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
public DateTime Date { get; set; }
public static async Task<Hours> LoadData() {
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(requestUrl, apiKey);
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", tokendata.apiKey);
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
hours = JsonConvert.DeserializeObject<Hours>(data);
//Preferences.Default.Set("name", hours.operator_api.name);
//Preferences.Default.Set("surname", hours.operator_api.surname);
}
return hours;
}
}
}