// if error, bad entry data private async void OnSave(object sender, EventArgs e) { await Navigation.PushModalAsync(new LoadingScreenPage()); var userList = await userManager.GetItemsAsync(); UserItem newUser = userList.First(); newUser.Birth = birthdayText.Date; if (!string.IsNullOrEmpty(weightText.Text)) { newUser.Weight = Convert.ToDouble(weightText.Text); } if (!string.IsNullOrEmpty(heightText.Text)) { newUser.Height = Convert.ToDouble(heightText.Text); } if (genderSwitch.IsToggled == true) { newUser.Gender = "F"; } try { await userManager.SaveItemAsync(newUser, true); } catch (Exception ex) { NotificationOptions options = new NotificationOptions(); IToastNotificator notificator = DependencyService.Get <IToastNotificator>(); var message = string.Format("{0}", ex.Message); options = Constants.NotificationStyle.Options(Constants.NotificationStyle.Which.Error); options.Description = message; await notificator.Notify(options); } await Navigation.PopModalAsync(); await Navigation.PopAsync(); }
public async void OnRegistration(object sender, EventArgs e) { if (!CrossConnectivity.Current.IsConnected) { return; } await Navigation.PushModalAsync(new LoadingScreenPage()); UserItemManager userManager = DBConnection.MainConnection.UserItem; UserItem newUser = new UserItem(); if (unitsSwitch.IsToggled == false) { Constants.AppUnitsType = "KM"; } else { Constants.AppUnitsType = "MI"; } newUser.Birth = birthdayText.Date; if (!string.IsNullOrEmpty(weightText.Text)) { newUser.Weight = Convert.ToDouble(weightText.Text); } if (!string.IsNullOrEmpty(heightText.Text)) { newUser.Height = Convert.ToDouble(heightText.Text); } if (genderSwitch.IsToggled == true) { newUser.Gender = "F"; } try { await userManager.SaveItemAsync(newUser, true); } catch (Exception ex) { await DBConnection.MainConnection.LogoutUser(); await Navigation.PopModalAsync(); OnBackButtonPressed(); var message = string.Format("{0}", ex.Message); options = Constants.NotificationStyle.Options(Constants.NotificationStyle.Which.Error); options.Description = message; await notificator.Notify(options); return; } await DBConnection.MainConnection.ConfirmUser(); await Navigation.PopModalAsync(); StartMainFunction(); }