56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
|
|
namespace Jugenddienst_Stunden.Models {
|
|
public class Operator : ObservableObject {
|
|
public string id;
|
|
public string name;
|
|
public string surname;
|
|
public string email;
|
|
public string password;
|
|
public string lang;
|
|
public string admin;
|
|
public string aktiv;
|
|
public string department;
|
|
public string department_name;
|
|
//public List<DateOnly>? timetable_begin;
|
|
/// <summary>
|
|
/// TimeTable Num
|
|
/// </summary>
|
|
public string num;
|
|
//public List<TimeOnly>? saved_overtime;
|
|
//public List<TimeOnly>? saved_holiday;
|
|
//public TimeOnly overtime;
|
|
//public TimeOnly holiday;
|
|
public string year;
|
|
//public List<int>? timetable;
|
|
|
|
|
|
|
|
|
|
public static async Task<Operator> LoadData(string apiKey) {
|
|
//var apiKey = Preferences.Default.Get("apiKey", "");
|
|
Operator OperatorVar = new Operator();
|
|
//Operator operator = new Operator();
|
|
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 {
|
|
var tokendata = new TokenData(apiKey);
|
|
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
|
if (data != null) {
|
|
OperatorVar = Newtonsoft.Json.JsonConvert.DeserializeObject<Operator>(data);
|
|
Preferences.Default.Set("name", OperatorVar.name);
|
|
Preferences.Default.Set("surname", OperatorVar.surname);
|
|
}
|
|
|
|
}
|
|
return OperatorVar;
|
|
}
|
|
}
|
|
}
|