protected async void ResendVerification(object sender, EventArgs e) { const string errorMessage = "Sorry, an error occurred when resending your verification code."; btnResend.IsVisible = false; prgResending.IsVisible = true; try { var response = await _authClient.ResendVerificationCode(); ToastService.Success(response.Message); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : errorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : errorMessage); } finally { btnResend.IsVisible = true; prgResending.IsVisible = false; } }
protected async void Remove(object sender, EventArgs e) { var response = await DisplayAlert("Confirm Removal", "Are you sure you want to remove this book. This action is irreversible.", "Proceed", "Cancel"); if (!response) { return; } const string genericErrorMessage = "Sorry, an error occurred when removing from your library. Try again later."; try { ToastService.Success("Removing from library..."); await _bookService.Remove(_book.Id); ToastService.Success("Book successfully removed from your library."); await Navigation.PopAsync(); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message : genericErrorMessage); } }
protected async void UpdatePassword(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when updating your password. Try again later."; var currentPassword = txtCurrentPassword.Text; var newPassword = txtNewPassword.Text; var confirmNewPassword = txtConfirmNewPassword.Text; if (string.IsNullOrWhiteSpace(currentPassword)) { ToastService.Error("A current password is required."); return; } if (string.IsNullOrWhiteSpace(newPassword)) { ToastService.Error("A new password is required."); return; } if (string.IsNullOrWhiteSpace(confirmNewPassword)) { ToastService.Error("A password confirmation is required."); return; } if (newPassword != confirmNewPassword) { ToastService.Error("The password and confirmation don't match."); return; } prgUpdatePassword.IsVisible = true; btnUpdatePassword.IsVisible = false; try { var response = await _userService.UpdatePassword(currentPassword, newPassword); ToastService.Success(response.Message); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message : genericErrorMessage); } finally { btnUpdatePassword.IsVisible = true; prgUpdatePassword.IsVisible = false; } }
protected async void Verify(object sender, EventArgs e) { const string errorMessage = "Sorry, an error occurred when verifying your email address. Try again later."; var verificationCode = txtVerificationCode.Text; if (string.IsNullOrWhiteSpace(verificationCode)) { ToastService.Error("A verification code is required."); return; } if (verificationCode.Length != Constants.VerificationCodeLength) { ToastService.Error($"Verification code must be {Constants.VerificationCodeLength} digits long."); return; } if (!verificationCode.All(char.IsDigit)) { ToastService.Error("Verification code can only contain digits."); return; } btnVerify.IsVisible = false; prgLoading.IsVisible = true; try { var response = await _authClient.VerifyEmail(verificationCode); TokenService.SetEmailVerified(true); ToastService.Success(response.Message); // go back to login Application.Current.MainPage = new NavigationPage(new Root()); await Navigation.PopAsync(); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : errorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : errorMessage); } finally { btnVerify.IsVisible = true; prgLoading.IsVisible = false; } }
protected async void Add(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when adding the item. Try again later."; var title = txtTitle.Text; var author = txtAuthor.Text; var isbn = txtIsbn.Text; if (string.IsNullOrWhiteSpace(title)) { ToastService.Error("A book title is required."); return; } if (string.IsNullOrWhiteSpace(author)) { ToastService.Error("An author name is required."); return; } stkBtns.IsVisible = false; prgAdding.IsVisible = true; try { var response = await _wishListService.Add(title, author, isbn); // notify user ToastService.Success("Book successfully added to your wish list."); // send data back Dismiss(response); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : genericErrorMessage); } finally { stkBtns.IsVisible = true; prgAdding.IsVisible = false; } }
protected async void Add(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when adding the book to your library. Try again later."; var title = txtTitle.Text; var summary = txtSummary.Text; var isbn = txtIsbn.Text; var publishYear = txtPublishYear.Text; var authors = txtAuthors.Text; var publisher = txtPublisher.Text; var pageCount = txtPageCount.Text; if (string.IsNullOrWhiteSpace(title)) { ToastService.Error("A title is required."); return; } stkBtns.IsVisible = false; prgAdding.IsVisible = true; try { await _bookService.AddManual(title, summary, isbn, publishYear, authors, publisher, pageCount); // notify user ToastService.Success("Book successfully added to your library."); // send data back Dismiss(""); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : genericErrorMessage); } finally { stkBtns.IsVisible = true; prgAdding.IsVisible = false; } }
private async void ScannerOnDisappearing(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when adding the book to your library. Try again later."; var scanner = sender as Scanner; var result = scanner?.ScanResult; // try disconnecting the event handler if (scanner != null) { scanner.Disappearing -= ScannerOnDisappearing; } if (string.IsNullOrEmpty(result)) { return; } try { // notify the user ToastService.Info($"Scanned ISBN: {result}. Adding to your library."); // call the service await _bookService.AddByIsbn(result); ToastService.Success("Book successfully added to your library"); // refresh the library await pageHome.LoadData(); await pageLibrary.LoadData(); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message : genericErrorMessage); } }
protected async void AttemptRequest(object sender, EventArgs e) { var email = txtEmail.Text; if (string.IsNullOrWhiteSpace(email)) { ToastService.Error("An email address is required."); return; } btnRequest.IsVisible = false; prgLoading.IsVisible = true; try { var response = await _authClient.ForgotPassword(email); ToastService.Success(response.Message); // go await Navigation.PushAsync(new ResetPassword(email)); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : "Sorry, an error occurred when requesting a reset code. Try again later."); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : "Sorry, an error occurred when requesting a reset code. Try again later."); } finally { btnRequest.IsVisible = true; prgLoading.IsVisible = false; } }
protected async void Add(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when adding the book to your library. Try again later."; var isbn = txtIsbn.Text; if (string.IsNullOrWhiteSpace(isbn)) { ToastService.Error("An isbn is required."); return; } stkBtns.IsVisible = false; prgAdding.IsVisible = true; try { await _bookService.AddByIsbn(isbn); // notify user ToastService.Success("Book successfully added to your library."); // send data back Dismiss(""); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : genericErrorMessage); } finally { stkBtns.IsVisible = true; prgAdding.IsVisible = false; } }
protected async void UpdateProfile(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when updating your information. Try again later."; prgUpdateProfile.IsVisible = true; btnUpdateProfile.IsVisible = false; var firstName = txtFirstName.Text; var lastName = txtLastName.Text; try { var user = await _userService.UpdateProfile(firstName, lastName); // update the details locally TokenService.SetUserDetails(user.FirstName, user.LastName); // notify user ToastService.Success("Profile updated successfully."); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message : genericErrorMessage); } finally { btnUpdateProfile.IsVisible = true; prgUpdateProfile.IsVisible = false; } }
private void CopyTransactionHash() { ClipboardService.SetText(Transaction.TransactionId); ToastService.Success("Transaction ID 复制成功"); }
private void CopyBlockHash() { ClipboardService.SetText(Transaction.BlockHash); ToastService.Success("Block Hash 复制成功"); }
protected async void Reset(object sender, EventArgs e) { const string errorMessage = "Sorry, an error occurred when requesting a reset code. Try again later."; var resetCode = txtResetCode.Text; var password = txtPassword.Text; var confirmPassword = txtConfirmPassword.Text; if (string.IsNullOrWhiteSpace(resetCode)) { ToastService.Error("A reset code is required."); return; } if (resetCode.Length != Constants.ResetCodeLength) { ToastService.Error($"Reset code must be {Constants.ResetCodeLength} digits long."); return; } if (!resetCode.All(char.IsDigit)) { ToastService.Error("Reset code can only contain digits."); return; } if (string.IsNullOrWhiteSpace(password)) { ToastService.Error("A password is required."); return; } if (string.IsNullOrWhiteSpace(confirmPassword)) { ToastService.Error("A password confirmation is required."); return; } if (password != confirmPassword) { ToastService.Error("The password and confirmation don't match."); return; } btnReset.IsVisible = false; prgLoading.IsVisible = true; try { var response = await _authClient.ResetPassword(_emailAddress, resetCode, password); ToastService.Success(response.Message); // go back to login Navigation.InsertPageBefore(new Login(), this); await Navigation.PopAsync(); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : errorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : errorMessage); } finally { btnReset.IsVisible = true; prgLoading.IsVisible = false; } }
protected async void AttemptLogin(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when logging you in. Try again later."; var email = txtEmail.Text; var password = txtPassword.Text; if (string.IsNullOrWhiteSpace(email)) { ToastService.Error("An email address is required."); return; } if (string.IsNullOrWhiteSpace(password)) { ToastService.Error("A password is required."); return; } btnLogin.IsVisible = false; prgLoading.IsVisible = true; try { var response = await _authClient.Login(email, password); TokenService.SetUserDetails(response.FirstName, response.LastName); TokenService.SetEmail(response.EmailAddress); TokenService.SetEmailVerified(response.IsEmailVerified); await TokenService.SetAuthToken(response.AuthToken); ToastService.Success("Logged in successfully."); if (response.IsEmailVerified) { // send to home page Navigation.InsertPageBefore(new Root(), this); await Navigation.PopAsync(); } else { await Navigation.PushAsync(new VerifyEmail()); } } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : genericErrorMessage); } finally { btnLogin.IsVisible = true; prgLoading.IsVisible = false; } }
protected async void AttemptRegister(object sender, EventArgs e) { const string genericErrorMessage = "Sorry, an error occurred when registering you. Try again later."; var fullName = txtFullName.Text; var email = txtEmail.Text; var password = txtPassword.Text; var confirmPassword = txtConfirmPassword.Text; if (string.IsNullOrWhiteSpace(email)) { ToastService.Error("An email address is required."); return; } if (string.IsNullOrWhiteSpace(password)) { ToastService.Error("A password is required."); return; } if (string.IsNullOrWhiteSpace(confirmPassword)) { ToastService.Error("A password confirmation is required."); return; } if (password != confirmPassword) { ToastService.Error("The password and confirmation don't match."); return; } btnRegister.IsVisible = false; prgLoading.IsVisible = true; try { var response = await _authClient.Register(fullName, email, password); TokenService.SetUserDetails(response.FirstName, response.LastName); TokenService.SetEmail(email); TokenService.SetEmailVerified(response.IsEmailVerified); await TokenService.SetAuthToken(response.AuthToken); ToastService.Success("Account created successfully."); // send to verification page await Navigation.PushAsync(new VerifyEmail()); } catch (ApiException ex) when(ex.IsValidationException()) { var error = await ex.GetContentAsAsync <ValidationErrorViewModel>(); ToastService.Error(error?.Message?.Length > 0 ? error.Message[0] : genericErrorMessage); } catch (ApiException ex) { var error = await ex.GetContentAsAsync <ErrorViewModel>(); ToastService.Error(!string.IsNullOrWhiteSpace(error?.Message) ? error.Message : genericErrorMessage); } finally { btnRegister.IsVisible = true; prgLoading.IsVisible = false; } }