You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.2 KiB

1 year ago
  1. using GMCabsDriverAssistant.Services;
  2. using GMCabsDriverAssistantSolution.Views;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace GMCabsDriverAssistantSolution.ViewModels
  9. {
  10. [QueryProperty(nameof(PhoneNumber), nameof(PhoneNumber))]
  11. public class UserRegistrationVerifyOtpViewModel : BaseViewModel
  12. {
  13. #region Fields
  14. private string phoneNumber;
  15. private string step1;
  16. private string step2;
  17. private string step3;
  18. private string step4;
  19. private string errorMessage;
  20. #endregion
  21. #region Properties
  22. public string PhoneNumber
  23. {
  24. get => phoneNumber;
  25. set => phoneNumber = value;
  26. }
  27. public string Step1
  28. {
  29. get => step1;
  30. set
  31. {
  32. SetProperty(ref step1, value);
  33. ErrorMessage = string.Empty;
  34. }
  35. }
  36. public string Step2
  37. {
  38. get => step2;
  39. set
  40. {
  41. SetProperty(ref step2, value);
  42. ErrorMessage = string.Empty;
  43. }
  44. }
  45. public string Step3
  46. {
  47. get => step3;
  48. set
  49. {
  50. SetProperty(ref step3, value);
  51. ErrorMessage = string.Empty;
  52. }
  53. }
  54. public string Step4
  55. {
  56. get => step4;
  57. set
  58. {
  59. SetProperty(ref step4, value);
  60. ErrorMessage = string.Empty;
  61. }
  62. }
  63. public string ErrorMessage
  64. {
  65. get => errorMessage;
  66. set => SetProperty(ref errorMessage, value);
  67. }
  68. public Command VerifyOtp { get; set; }
  69. public Command Back { get; set; }
  70. #endregion
  71. #region Constructor
  72. public UserRegistrationVerifyOtpViewModel()
  73. {
  74. VerifyOtp = new Command(OnVerifyOtpClicked);
  75. Back = new Command(OnBackClicked);
  76. }
  77. #endregion
  78. #region Methods
  79. private async void OnVerifyOtpClicked(object obj)
  80. {
  81. ErrorMessage = "";
  82. if (string.IsNullOrWhiteSpace(Step1) || string.IsNullOrWhiteSpace(Step2) || string.IsNullOrWhiteSpace(Step3) || string.IsNullOrWhiteSpace(Step4))
  83. {
  84. ErrorMessage = "OTP required for Registration";
  85. return;
  86. }
  87. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  88. var otp = Step1 + Step2 + Step3 + Step4;
  89. var isOtpVerified = await gmCabsDriverService.VerifyOtp(PhoneNumber, otp);
  90. if (!isOtpVerified)
  91. {
  92. ErrorMessage = "OTP is incorrect";
  93. return;
  94. }
  95. await Shell.Current.GoToAsync($"//{nameof(LoginPage)}/{nameof(UserRegistrationGenerateOtpPage)}/{nameof(UserRegistrationVerifyOtpPage)}/{nameof(UserRegistrationUpdateDriverPinPage)}?{nameof(UserRegistrationUpdateDriverPinViewModel.PhoneNumber)}={phoneNumber}");
  96. }
  97. private async void OnBackClicked(object obj)
  98. {
  99. await Shell.Current.GoToAsync("..");
  100. }
  101. #endregion
  102. }
  103. }