Errorhandling Token problems
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Jugenddienst_Stunden.Models {
|
||||
//public List<int>? timetable;
|
||||
|
||||
|
||||
|
||||
public event EventHandler<string> AlertEvent;
|
||||
|
||||
public static async Task<Operator> LoadData(string apiKey) {
|
||||
//var apiKey = Preferences.Default.Get("apiKey", "");
|
||||
@@ -41,12 +41,25 @@ namespace Jugenddienst_Stunden.Models {
|
||||
//throw new Exception("Keine Internetverbindung");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
//try {
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
||||
if (data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -41,12 +41,18 @@ namespace Jugenddienst_Stunden.Models
|
||||
//apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
||||
//name = "Chri";
|
||||
//surname = "Fe";
|
||||
apiKey = "MTI3fDEyYURVdHVZVWRaZk91eDlNcjZDUFlTdmdkNHxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
||||
name = "Ju";
|
||||
surname = "Ze";
|
||||
Preferences.Default.Set("apiKey", apiKey);
|
||||
Preferences.Default.Set("name", name);
|
||||
Preferences.Default.Set("surname", surname);
|
||||
//apiKey = "MTI3fDEyYURVdHVZVWRaZk91eDlNcjZDUFlTdmdkNHxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=";
|
||||
//name = "Ju";
|
||||
//surname = "Ze";
|
||||
|
||||
//apiKey = "M3wvK09XQkZod1l4SXlVcGVWazdlUmYrTnBWaUl8aHR0cHM6Ly9ob3Vycy5waWRhLmluZm8vYXBwYXBp";
|
||||
//name = "Le";
|
||||
//surname = "Ma";
|
||||
|
||||
|
||||
//Preferences.Default.Set("apiKey", apiKey);
|
||||
//Preferences.Default.Set("name", name);
|
||||
//Preferences.Default.Set("surname", surname);
|
||||
|
||||
|
||||
Hours hours = new Hours();
|
||||
@@ -64,6 +70,9 @@ namespace Jugenddienst_Stunden.Models
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
if(data == "\"Lalala\"") {
|
||||
throw new Exception("Problem mit Token");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
//Preferences.Default.Set("name", hours.operator_api.name);
|
||||
|
||||
@@ -71,7 +71,9 @@ namespace Jugenddienst_Stunden.ViewModels {
|
||||
GetDay = dateToday.Day;
|
||||
OnPropertyChanged();
|
||||
_ = 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() {
|
||||
try {
|
||||
_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) {
|
||||
AlertEvent?.Invoke(this, e.Message);
|
||||
}
|
||||
//Models.Hours Hours = new Models.Hours();
|
||||
//Title = _hour.operator_api.name + " " + _hour.operator_api.surname;
|
||||
if (_hour != null) {
|
||||
TimeDay = _hour.zeit_total_daily_api.Where(p => p.Day == GetDay).ToList();
|
||||
RefreshProperties();
|
||||
}
|
||||
|
||||
|
||||
//if (_hour.zeit_total_daily_api != null) {
|
||||
// try {
|
||||
// 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() {
|
||||
|
||||
@@ -37,11 +37,13 @@
|
||||
<DatePicker Grid.Column="0" MinimumDate="{Binding MinimumDate}"
|
||||
MaximumDate="{Binding MaximumDate}"
|
||||
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 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>
|
||||
<Picker x:Name="pick_projekt" Title="Projekt" ItemsSource="{Binding OptionsProjekt}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" Grid.Column="1" >
|
||||
@@ -50,13 +52,24 @@
|
||||
</Picker>
|
||||
</Grid>
|
||||
<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" />
|
||||
|
||||
<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>
|
||||
|
||||
<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="{Binding ShowDay}"></Label>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user