async Task SignIn() { try { #if DEBUG if ((bool)Application.Current.Resources["LoginOk"]) { Application.Current.MainPage = new MasterPage() { IsPresented = true }; return; } #endif if (!ValidateInformation()) { await Application.Current.MainPage.DisplayAlert("Aviso", "Verifica que todos los campos se encuentren completos.", "Aceptar"); } else if (!IsBusy) { IsBusy = true; //clean any previous session SignOutPage.CleanCurrentSession(); //launch task SignInAccountRequest model = new SignInAccountRequest() { username = Username, password = Password }; SignInAccountResponse response = await RestHelper.SignInAccountAsync(model); if (response.Status != ResponseStatus.Ok) { await Application.Current.MainPage.DisplayAlert("Error", response.Message, "Aceptar"); } else { Settings.Profile_Username = response.Username; Settings.Profile_Picture = $"{Settings.ImageStorageUrl}/{Settings.AccountImageStorageUrl}/{response.Image}"; IsBusy = false; await Task.Delay(10); Application.Current.MainPage = new MasterPage() { IsPresented = true }; } IsBusy = false; } } catch (Exception ex) { Microsoft.AppCenter.Crashes.Crashes.TrackError(ex); await Application.Current.MainPage.DisplayAlert("Error", "Ocurrió un error inesperado", "Aceptar"); } }
async Task InitializeViewModel() { ContinueCommand = new Command(() => Continue()); ContinueGoBackCommand = new Command(() => ContinueGoBack()); IsBusy = true; IsContinueEnabled = false; IsContinueGoBackEnabled = false; MessageTitle = "Por favor aguarda, estamos creando tu cuenta..."; try { //clean any previous session SignOutPage.CleanCurrentSession(); //launch task SignUpAccountResponse response = await RestHelper.SignUpAccountAsync(model); if (response.Status == ResponseStatus.Ok) { Settings.Profile_Username = model.username.ToLower(); Settings.Profile_Picture = $"{Settings.ImageStorageUrl}/{Settings.AccountImageStorageUrl}/{response.Image}"; IsBusy = false; IsContinueEnabled = true; IsContinueGoBackEnabled = false; MessageTitle = $"¡Gracias {Settings.Profile_Username}!"; MessageSubTitle = "Tu cuenta ha sido creada satisfactoriamente."; } else { IsBusy = false; IsContinueEnabled = false; IsContinueGoBackEnabled = true; MessageTitle = "El proceso de registro no fue satisfactorio."; MessageSubTitle = response.Message; } } catch (Exception ex) { Microsoft.AppCenter.Crashes.Crashes.TrackError(ex); IsBusy = false; IsContinueEnabled = false; IsContinueGoBackEnabled = true; MessageTitle = "El proceso de registro no fue satisfactorio."; MessageSubTitle = "Ocurrió un error inesperado"; } }