42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.Maui.Networking;
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
|
namespace Jugenddienst_Stunden.Models {
|
|
internal class Stunde : ObservableObject {
|
|
|
|
private static readonly string BaseAddress = "http://hours.dauni.mine.nu:81";
|
|
//private static readonly string apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Christine
|
|
private static readonly string apiKey = "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Damian
|
|
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");
|
|
//throw new Exception("Keine Internetverbindung");
|
|
} else {
|
|
string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
|
|
|
if (data == null) {
|
|
throw new Exception("Keine Daten erhalten");
|
|
}
|
|
|
|
hours = JsonConvert.DeserializeObject<Hours>(data);
|
|
|
|
}
|
|
return hours;
|
|
}
|
|
|
|
|
|
}
|
|
}
|