Namespaceanpassungen
This commit is contained in:
@@ -1,175 +1,196 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Maui.Networking;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
|
||||
internal class Stunde : ObservableObject {
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
//Default-Werte zum Testen
|
||||
public static string apiKey = Preferences.Default.Get("apiKey", "M3xraUdoSktrdGowaUZoaStJbDJLWmIyTFhYeDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
||||
public static int EmployeeId = Preferences.Default.Get("employeeId", 3);
|
||||
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", "http://hours.dauni.mine.nu:81/appapi");
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
internal class Stunde : ObservableObject {
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
public static async Task<Hours> LoadData() {
|
||||
Preferences.Default.Set("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
||||
Preferences.Default.Set("name", "Johannes");
|
||||
Preferences.Default.Set("surname", "Fink");
|
||||
Preferences.Default.Set("EmployeeId", 5);
|
||||
Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
||||
|
||||
//Default-Werte zum Testen
|
||||
apiKey = Preferences.Default.Get("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
|
||||
EmployeeId = Preferences.Default.Get("employeeId", 5);
|
||||
name = Preferences.Default.Get("name", "Johannes");
|
||||
surname = Preferences.Default.Get("surname", "Fink");
|
||||
apiUrl = Preferences.Default.Get("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
|
||||
|
||||
|
||||
//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", "");
|
||||
public static int EmployeeId = Preferences.Default.Get("employeeId", 3);
|
||||
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
|
||||
//public static string apiKey = Preferences.Default.Get("apiKey", "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
|
||||
//private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
|
||||
|
||||
//public static string apiKey = "Mnx6amdpUkFCdWMvc0lmZ3dWeXRVSWx3VGRDRDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"; //Daniel Pichler
|
||||
//public static string apiKey = "M3xraUdoSktrdGowaUZoaStJbDJLWmIyTFhYeDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"; //Le Mair
|
||||
|
||||
|
||||
public static async Task<Hours> LoadData() {
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
|
||||
}
|
||||
return hours;
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
|
||||
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) {
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
List<DayTime> daytimes = new List<DayTime>();
|
||||
|
||||
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 + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
|
||||
|
||||
if (data == "null") {
|
||||
throw new Exception("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
//daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data);
|
||||
daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
|
||||
|
||||
|
||||
}
|
||||
//Hours = hours;
|
||||
return daytimes;
|
||||
}
|
||||
|
||||
public static async Task<DayTime> LoadEntry(int id) {
|
||||
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);
|
||||
var data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
|
||||
|
||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data);
|
||||
hours.TimeSpanVon = hours.begin.ToTimeSpan();
|
||||
hours.TimeSpanBis = hours.end.ToTimeSpan();
|
||||
//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");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
public static Stunde Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||
|
||||
return
|
||||
new() {
|
||||
//Filename = Path.GetFileName(filename),
|
||||
//Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
|
||||
public static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
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;
|
||||
}
|
||||
return hours;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basisdaten: Mitarbeiterdaten, Projekte, Gemeinden, Freistellungen.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Zeiten eines Tages holen
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public static async Task<List<DayTime>> LoadDay(DateTime date) {
|
||||
if (string.IsNullOrEmpty(apiKey)) {
|
||||
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
|
||||
}
|
||||
List<DayTime> daytimes = new List<DayTime>();
|
||||
|
||||
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 + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
|
||||
|
||||
if (data == "null") {
|
||||
throw new Exception("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
|
||||
}
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
//daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data);
|
||||
daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
|
||||
|
||||
|
||||
}
|
||||
//Hours = hours;
|
||||
return daytimes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Einzelnen Stundeneintrag holen
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<DayTime> LoadEntry(int id) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
var data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
|
||||
|
||||
//DayTime hours = Hours.daytime.Find(x => x.id == id);
|
||||
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data);
|
||||
hours.TimeSpanVon = hours.begin.ToTimeSpan();
|
||||
hours.TimeSpanBis = hours.end.ToTimeSpan();
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
|
||||
public static Stunde Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||
|
||||
return
|
||||
new() {
|
||||
//Filename = Path.GetFileName(filename),
|
||||
//Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eintrag speichern
|
||||
/// </summary>
|
||||
/// <param name="stunde"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<DayTime> SaveEntry(DayTime stunde) { //, string begin, string end, string freistellung, string bemerkung) {
|
||||
|
||||
var tokendata = new TokenData(apiKey);
|
||||
bool isNew = false;
|
||||
if (stunde.id == null)
|
||||
isNew = true;
|
||||
await Auth.SaveItemAsync(tokendata.url, tokendata.apiKey, stunde, isNew);
|
||||
|
||||
return stunde;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Eintrag löschen
|
||||
/// </summary>
|
||||
/// <param name="stunde"></param>
|
||||
/// <returns></returns>
|
||||
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