public Registration() { _model = new Model.Registration(); GoToLogin = new Command(() => { Application.Current.MainPage = new View.Login(); }); Register = new Command(async() => { Func <string, Task> mention_about_error = async(string message) => await Application.Current.MainPage.DisplayAlert("Ошибка!", message, "Ок"); try { Data.User data = await _model.Register(Application.Current.Resources["url"] as string); if (data != null) { data.Bind(Application.Current.Properties); await Application.Current.SavePropertiesAsync(); Application.Current.MainPage = new View.Master(); } } catch (Exception e) { if (e is Exceptions.PasswordsMismatch) { await mention_about_error("Пароли не совпадают"); } else if (e is Exceptions.EmptyField) { await mention_about_error("Одно или несколько полей пусты"); } else if (e is Exceptions.EmailAlreadyTaken) { await mention_about_error("Пользвотель с данной почтой уже зарегестирован"); } else if (e is Exceptions.NotEmail) { await mention_about_error("Пожалуйста, введите корректный email"); } else { await mention_about_error($"Неизвестная ошибка - {e.Message}"); } } }); }
public Login() { _model = new Model.Login(); GoToRegister = new Command(() => { Application.Current.MainPage = new View.Registration(); }); LogIn = new Command(async() => { Func <string, Task> mention_about_error = async(string message) => await Application.Current.MainPage.DisplayAlert("Ошибка!", message, "OK"); try { Data.User data = await _model.LogIn(Application.Current.Resources["url"] as string); if (data != null) { data.Bind(Application.Current.Properties); await Application.Current.SavePropertiesAsync(); Application.Current.MainPage = new View.Master(); } } catch (Exception e) { if (e is Exceptions.EmptyField) { await mention_about_error("Одно или несколько полей пусты"); } else if (e is Exceptions.NotEmail) { await mention_about_error("Пожалуйста, введите корректную почту"); } else if (e is Exceptions.LoginEmailNotFound) { await mention_about_error("Пользователь с данным логином или почтой не найден"); } else if (e is Exceptions.InccorrectPassword) { await mention_about_error("Неверный пароль"); } else { await mention_about_error($"Неизвестная ошибка - {e}\n\n {e.Message}"); } } }); }