Show error if not logged in

This commit is contained in:
2024-09-27 11:16:27 +02:00
parent ec7f563bc0
commit 5f3e80dcc7
2 changed files with 16 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ namespace Jugenddienst_Stunden.Models {
//public static string surname = Preferences.Default.Get("surname", "Weger"); //public static string surname = Preferences.Default.Get("surname", "Weger");
//Christine Feichter //Christine Feichter
public static string apiKey = Preferences.Default.Get("apiKey", "M3xraUdoSktrdGowaUZoaStJbDJLWmIyTFhYeDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"); public static string apiKey = Preferences.Default.Get("apiKey", "");
public static int EmployeeId = Preferences.Default.Get("employeeId", 3); public static int EmployeeId = Preferences.Default.Get("employeeId", 3);
public static string name = Preferences.Default.Get("name", "Vorname"); public static string name = Preferences.Default.Get("name", "Vorname");
public static string surname = Preferences.Default.Get("surname", "Nachname"); public static string surname = Preferences.Default.Get("surname", "Nachname");
@@ -34,11 +34,13 @@ namespace Jugenddienst_Stunden.Models {
//private static readonly string requestUrl = $"{BaseAddress}/appapi?hours"; //private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
//public static string apiKey = "Mnx6amdpUkFCdWMvc0lmZ3dWeXRVSWx3VGRDRDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"; //Daniel Pichler //public static string apiKey = "Mnx6amdpUkFCdWMvc0lmZ3dWeXRVSWx3VGRDRDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"; //Daniel Pichler
//public static string apiKey = "M3xraUdoSktrdGowaUZoaStJbDJLWmIyTFhYeDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"; //Daniel Pichler //public static string apiKey = "M3xraUdoSktrdGowaUZoaStJbDJLWmIyTFhYeDh8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp"; //Le Mair
public static async Task<Hours> LoadData() { public static async Task<Hours> LoadData() {
if (string.IsNullOrEmpty(apiKey)) {
throw new Exception("Kein APIKEY, bitte zuerst Login durchführen");
}
Hours hours = new Hours(); Hours hours = new Hours();
@@ -93,7 +95,9 @@ namespace Jugenddienst_Stunden.Models {
} }
public static async Task<List<DayTime>> LoadDay(DateTime date) { 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>(); List<DayTime> daytimes = new List<DayTime>();
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) { if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
@@ -122,7 +126,6 @@ namespace Jugenddienst_Stunden.Models {
return daytimes; return daytimes;
} }
public static async Task<DayTime> LoadEntry(int id) { public static async Task<DayTime> LoadEntry(int id) {
var tokendata = new TokenData(apiKey); var tokendata = new TokenData(apiKey);
@@ -136,7 +139,6 @@ namespace Jugenddienst_Stunden.Models {
return hours; return hours;
} }
public static Stunde Load(string filename) { public static Stunde Load(string filename) {
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename); filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);

View File

@@ -8,6 +8,7 @@ using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using Jugenddienst_Stunden.Types; using Jugenddienst_Stunden.Types;
using System.Globalization; using System.Globalization;
using System;
namespace Jugenddienst_Stunden.ViewModels { namespace Jugenddienst_Stunden.ViewModels {
@@ -115,10 +116,11 @@ namespace Jugenddienst_Stunden.ViewModels {
public List<TimeDay> TimeDay { get; set; } public List<TimeDay> TimeDay { get; set; }
public static string apiKey = Preferences.Default.Get("apiKey", "");
public StundenViewModel() { public StundenViewModel() {
_hour = new Types.Hours(); _hour = new Types.Hours();
LoadDataCommand = new AsyncRelayCommand(LoadData); LoadDataCommand = new AsyncRelayCommand(LoadData);
@@ -129,6 +131,7 @@ namespace Jugenddienst_Stunden.ViewModels {
OnPropertyChanged(nameof(DayTimes)); OnPropertyChanged(nameof(DayTimes));
} }
private async Task NewEntryAsync() { private async Task NewEntryAsync() {
//Hier muss das Datum übergeben werden //Hier muss das Datum übergeben werden
//await Shell.Current.GoToAsync(nameof(Views.StundePage)); //await Shell.Current.GoToAsync(nameof(Views.StundePage));
@@ -158,7 +161,8 @@ namespace Jugenddienst_Stunden.ViewModels {
////TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay.Day).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay.Day, Hours = 0 } }; ////TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay.Day).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay.Day, Hours = 0 } };
//RefreshProperties(); //RefreshProperties();
//Hier werden im Moment noch nur die eingetragenen Stunden gezählt
//Auf der Website bekommt der Benutzer die berechneten Stunden angezeigt (Nachstunden außerhalb des Stundenplanes zählen mehr ...)
TimeSpan span = TimeSpan.Zero; TimeSpan span = TimeSpan.Zero;
foreach (DayTime dt in _hour.daytime) { foreach (DayTime dt in _hour.daytime) {
span += dt.end - dt.begin; span += dt.end - dt.begin;
@@ -171,6 +175,8 @@ namespace Jugenddienst_Stunden.ViewModels {
////} ////}
} catch (Exception e) { } catch (Exception e) {
DayTimes = new List<DayTime>(); DayTimes = new List<DayTime>();
DayTotal = new TimeOnly(0);
OnPropertyChanged(nameof(DayTotal));
InfoEvent?.Invoke(this, e.Message); InfoEvent?.Invoke(this, e.Message);
} }
} }