Errorhandling Token problems
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Jugenddienst_Stunden.Models {
|
|||||||
//public List<int>? timetable;
|
//public List<int>? timetable;
|
||||||
|
|
||||||
|
|
||||||
|
public event EventHandler<string> AlertEvent;
|
||||||
|
|
||||||
public static async Task<Operator> LoadData(string apiKey) {
|
public static async Task<Operator> LoadData(string apiKey) {
|
||||||
//var apiKey = Preferences.Default.Get("apiKey", "");
|
//var apiKey = Preferences.Default.Get("apiKey", "");
|
||||||
@@ -41,12 +41,25 @@ namespace Jugenddienst_Stunden.Models {
|
|||||||
//throw new Exception("Keine Internetverbindung");
|
//throw new Exception("Keine Internetverbindung");
|
||||||
} else {
|
} else {
|
||||||
var tokendata = new TokenData(apiKey);
|
var tokendata = new TokenData(apiKey);
|
||||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
//try {
|
||||||
if (data != null) {
|
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
||||||
OperatorVar = Newtonsoft.Json.JsonConvert.DeserializeObject<Operator>(data);
|
if (data == "\"Lalala\"") {
|
||||||
Preferences.Default.Set("name", OperatorVar.name);
|
throw new Exception("Problem mit Token");
|
||||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
}
|
||||||
}
|
if (data != null) {
|
||||||
|
OperatorVar = Newtonsoft.Json.JsonConvert.DeserializeObject<Operator>(data);
|
||||||
|
Preferences.Default.Set("name", OperatorVar.name);
|
||||||
|
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||||
|
}
|
||||||
|
//} catch (Exception e) {
|
||||||
|
// //AlertEvent?.Invoke(this, e.Message);
|
||||||
|
// await App.Current.MainPage.DisplayAlert("Fehler",
|
||||||
|
// e.Message,
|
||||||
|
// "OK");
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return OperatorVar;
|
return OperatorVar;
|
||||||
|
|||||||
@@ -41,12 +41,18 @@ namespace Jugenddienst_Stunden.Models
|
|||||||
//apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
//apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
||||||
//name = "Chri";
|
//name = "Chri";
|
||||||
//surname = "Fe";
|
//surname = "Fe";
|
||||||
apiKey = "MTI3fDEyYURVdHVZVWRaZk91eDlNcjZDUFlTdmdkNHxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
//apiKey = "MTI3fDEyYURVdHVZVWRaZk91eDlNcjZDUFlTdmdkNHxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
||||||
name = "Ju";
|
//name = "Ju";
|
||||||
surname = "Ze";
|
//surname = "Ze";
|
||||||
Preferences.Default.Set("apiKey", apiKey);
|
|
||||||
Preferences.Default.Set("name", name);
|
//apiKey = "M3wvK09XQkZod1l4SXlVcGVWazdlUmYrTnBWaUl8aHR0cHM6Ly9ob3Vycy5waWRhLmluZm8vYXBwYXBp";
|
||||||
Preferences.Default.Set("surname", surname);
|
//name = "Le";
|
||||||
|
//surname = "Ma";
|
||||||
|
|
||||||
|
|
||||||
|
//Preferences.Default.Set("apiKey", apiKey);
|
||||||
|
//Preferences.Default.Set("name", name);
|
||||||
|
//Preferences.Default.Set("surname", surname);
|
||||||
|
|
||||||
|
|
||||||
Hours hours = new Hours();
|
Hours hours = new Hours();
|
||||||
@@ -64,10 +70,13 @@ namespace Jugenddienst_Stunden.Models
|
|||||||
if (data == null) {
|
if (data == null) {
|
||||||
throw new Exception("Keine Daten erhalten");
|
throw new Exception("Keine Daten erhalten");
|
||||||
}
|
}
|
||||||
|
if(data == "\"Lalala\"") {
|
||||||
|
throw new Exception("Problem mit Token");
|
||||||
|
}
|
||||||
|
|
||||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||||
//Preferences.Default.Set("name", hours.operator_api.name);
|
//Preferences.Default.Set("name", hours.operator_api.name);
|
||||||
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ namespace Jugenddienst_Stunden.ViewModels {
|
|||||||
GetDay = dateToday.Day;
|
GetDay = dateToday.Day;
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
_ = LoadData(); // Use discard operator to explicitly ignore the returned Task
|
_ = LoadData(); // Use discard operator to explicitly ignore the returned Task
|
||||||
RefreshProperties();
|
//RefreshProperties();
|
||||||
|
OnPropertyChanged(nameof(TimeDay));
|
||||||
|
OnPropertyChanged(nameof(ShowDay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,15 +146,29 @@ namespace Jugenddienst_Stunden.ViewModels {
|
|||||||
public async Task LoadData() {
|
public async Task LoadData() {
|
||||||
try {
|
try {
|
||||||
_hour = await Models.Stunde.LoadData();
|
_hour = await Models.Stunde.LoadData();
|
||||||
|
if (_hour.zeit_total_daily_api != null) {
|
||||||
|
TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay, Hours = 0 } };
|
||||||
|
RefreshProperties();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
AlertEvent?.Invoke(this, e.Message);
|
AlertEvent?.Invoke(this, e.Message);
|
||||||
}
|
}
|
||||||
//Models.Hours Hours = new Models.Hours();
|
|
||||||
//Title = _hour.operator_api.name + " " + _hour.operator_api.surname;
|
|
||||||
if (_hour != null) {
|
//if (_hour.zeit_total_daily_api != null) {
|
||||||
TimeDay = _hour.zeit_total_daily_api.Where(p => p.Day == GetDay).ToList();
|
// try {
|
||||||
RefreshProperties();
|
// TimeDay = _hour.zeit_total_daily_api.Where(static p => p.Day == GetDay).ToList() ?? new List<TimeDay> { new TimeDay { Day = GetDay, Hours = 0 } };
|
||||||
}
|
|
||||||
|
// RefreshProperties();
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// AlertEvent?.Invoke(this, e.Message);
|
||||||
|
// }
|
||||||
|
|
||||||
|
//} else {
|
||||||
|
// await App.Current.MainPage.DisplayAlert("Fehler",
|
||||||
|
// "zeit_total_daily_api ist leer",
|
||||||
|
// "OK");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshProperties() {
|
private void RefreshProperties() {
|
||||||
|
|||||||
@@ -9,59 +9,72 @@
|
|||||||
<models:StundenViewModel />
|
<models:StundenViewModel />
|
||||||
</ContentPage.BindingContext>
|
</ContentPage.BindingContext>
|
||||||
|
|
||||||
<VerticalStackLayout Spacing="10" Margin="15">
|
<VerticalStackLayout Spacing="10" Margin="15">
|
||||||
|
|
||||||
<Label Text="{Binding Message}" />
|
<Label Text="{Binding Message}" />
|
||||||
|
|
||||||
<Button Text="Lade aktuelle Daten" Command="{Binding LoadDataCommand}" />
|
<Button Text="Lade aktuelle Daten" Command="{Binding LoadDataCommand}" />
|
||||||
|
|
||||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*" Margin="10">
|
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*" Margin="10">
|
||||||
<Label Text="Soll:" Grid.Row="0" Background="DarkSalmon" />
|
<Label Text="Soll:" Grid.Row="0" Background="DarkSalmon" />
|
||||||
<Label Text="Gearbeitet:" Grid.Row="1" />
|
<Label Text="Gearbeitet:" Grid.Row="1" />
|
||||||
<Label Text="Berechnet:" Grid.Row="2" />
|
<Label Text="Berechnet:" Grid.Row="2" />
|
||||||
<Label Text="Überstunden Monat:" Grid.Row="3" Margin="0,0,15,0" />
|
<Label Text="Überstunden Monat:" Grid.Row="3" Margin="0,0,15,0" />
|
||||||
<Label Text="Überstunden Jahr:" Grid.Row="4" />
|
<Label Text="Überstunden Jahr:" Grid.Row="4" />
|
||||||
|
|
||||||
|
|
||||||
<Label Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Nominal}" Background="DarkSalmon" />
|
<Label Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Nominal}" Background="DarkSalmon" />
|
||||||
<Label Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitDone}" />
|
<Label Grid.Row="1" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitDone}" />
|
||||||
<Label Grid.Row="2" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitCalculated}" />
|
<Label Grid.Row="2" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding ZeitCalculated}" />
|
||||||
<Label Grid.Row="3" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding OvertimeMonth}" />
|
<Label Grid.Row="3" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding OvertimeMonth}" />
|
||||||
<Label Grid.Row="4" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Overtime}" />
|
<Label Grid.Row="4" Grid.Column="1" HorizontalTextAlignment="End" Padding="0,0,5,0" Text="{Binding Overtime}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
<BoxView HeightRequest="1" Color="Red"/>
|
<BoxView HeightRequest="1" Color="Red"/>
|
||||||
|
|
||||||
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*">
|
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*">
|
||||||
<DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}"
|
<DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}"
|
||||||
MaximumDate="{Binding MaximumDate}"
|
MaximumDate="{Binding MaximumDate}"
|
||||||
Date="{Binding DateToday}" Format="dddd, d. MMM. yyyy" />
|
Date="{Binding DateToday}" Format="dddd, d. MMM. yyyy" />
|
||||||
<Label Grid.Column="1" Text="{Binding TimeDay[0].Hours}" VerticalOptions="Center"></Label>
|
<Border Grid.Column="1" Margin="15,0,0,0" Padding="15,0,0,0">
|
||||||
|
<Label Text="{Binding TimeDay[0].Hours}" VerticalOptions="Center"></Label>
|
||||||
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
<Grid ColumnDefinitions="Auto,Auto,Auto">
|
<Grid ColumnDefinitions="*,*,*">
|
||||||
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding Options}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="0" >
|
<Picker x:Name="pick_gemeinde" Title="Gemeinde" ItemsSource="{Binding Options}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="0" >
|
||||||
</Picker>
|
</Picker>
|
||||||
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="1" >
|
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="1" >
|
||||||
</Picker>
|
</Picker>
|
||||||
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="2" >
|
<Picker x:Name="pick_freistellung" Title="Freistellung" ItemsSource="{Binding OptionsFreistellung}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="2" >
|
||||||
</Picker>
|
</Picker>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Entry x:Name="entry" Placeholder="Tätigkeit" />
|
<Entry x:Name="entry" Placeholder="Tätigkeit" />
|
||||||
<Grid ColumnDefinitions="2*,Auto,2*,Auto">
|
|
||||||
<Label Text="Beginn" Grid.Column="0" Background="LightGreen" TextColor="Gray" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0"></Label>
|
|
||||||
<TimePicker HorizontalOptions="Center" Grid.Column="1" Background="LightGreen" TextColor="Gray" />
|
<FlexLayout Direction="Row" AlignItems="Start" Wrap="Wrap">
|
||||||
|
<Border Background="LightGreen">
|
||||||
|
<HorizontalStackLayout>
|
||||||
|
<Label Text="Beginn" TextColor="Gray" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,13"></Label>
|
||||||
|
<TimePicker HorizontalOptions="Center" TextColor="Gray" Format="HH:mm" MinimumWidthRequest="80" />
|
||||||
|
</HorizontalStackLayout>
|
||||||
|
</Border>
|
||||||
|
<Border Background="OrangeRed">
|
||||||
|
<HorizontalStackLayout>
|
||||||
|
<Label Text="Ende" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0" Margin="5,0,0,13"></Label>
|
||||||
|
<TimePicker TextColor="White" Format="HH:mm" MinimumWidthRequest="80" />
|
||||||
|
</HorizontalStackLayout>
|
||||||
|
</Border>
|
||||||
|
</FlexLayout>
|
||||||
|
|
||||||
|
|
||||||
<Label Text="Ende" Grid.Column="2" Background="OrangeRed" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Padding="0,0,10,0"></Label>
|
|
||||||
<TimePicker HorizontalOptions="Center" Grid.Column="3" Background="OrangeRed" TextColor="White" />
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<Label Text="{Binding ShowDay}"></Label>
|
<Label Text="{Binding ShowDay}"></Label>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
|
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
Reference in New Issue
Block a user