122 lines
3.9 KiB
C#
122 lines
3.9 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.Maui.Networking;
|
|
using Microsoft.Maui.Controls;
|
|
using System;
|
|
using System.Text;
|
|
using Jugenddienst_Stunden.Types;
|
|
|
|
|
|
namespace Jugenddienst_Stunden.Models
|
|
{
|
|
internal class Stunde : ObservableObject {
|
|
|
|
//Default-Werte zum Testen
|
|
|
|
//Katharina
|
|
//public static string apiKey = Preferences.Default.Get("apiKey", "MTAyfEJZZnB1L3VwcnhoVms0dDlLZENPZWtUVy85b3xodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
|
//public static string name = Preferences.Default.Get("name", "Katharina");
|
|
//public static string surname = Preferences.Default.Get("surname", "Weger");
|
|
|
|
//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");
|
|
|
|
//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() {
|
|
|
|
//Temporär fix für virtuelle App
|
|
//apiKey = "MTAyfEJZZnB1L3VwcnhoVms0dDlLZENPZWtUVy85b3xodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
|
//name = "Kathi";
|
|
//surname = "Wegi";
|
|
//apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
|
//name = "Chri";
|
|
//surname = "Fe";
|
|
//apiKey = "MTI3fDEyYURVdHVZVWRaZk91eDlNcjZDUFlTdmdkNHxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
|
//name = "Ju";
|
|
//surname = "Ze";
|
|
|
|
//apiKey = "M3wvK09XQkZod1l4SXlVcGVWazdlUmYrTnBWaUl8aHR0cHM6Ly9ob3Vycy5waWRhLmluZm8vYXBwYXBp";
|
|
//name = "Le";
|
|
//surname = "Ma";
|
|
|
|
|
|
//Preferences.Default.Set("apiKey", apiKey);
|
|
//Preferences.Default.Set("name", name);
|
|
//Preferences.Default.Set("surname", surname);
|
|
|
|
|
|
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&month=8", 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);
|
|
//Preferences.Default.Set("name", hours.operator_api.name);
|
|
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
|
|
|
|
|
}
|
|
return hours;
|
|
}
|
|
|
|
|
|
public static async Task<Hours> LoadDay(DateTime date) {
|
|
|
|
|
|
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&date="+date.ToString("yyyy-MM-dd"), 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);
|
|
//Preferences.Default.Set("name", hours.operator_api.name);
|
|
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
|
|
|
|
|
}
|
|
return hours;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|