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.

176 lines
5.4 KiB

  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Services;
  3. using GMCabsDriverAssistantSolution.Models.Rydo;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace GMCabsDriverAssistantSolution.ViewModels
  11. {
  12. [QueryProperty(nameof(BookingId), nameof(BookingId))]
  13. [QueryProperty(nameof(PickUpAddress), nameof(PickUpAddress))]
  14. [QueryProperty(nameof(DropUpAddress), nameof(DropUpAddress))]
  15. [QueryProperty(nameof(IsFutureBooking), nameof(IsFutureBooking))]
  16. [Obsolete]
  17. public class AcceptBookingViewModel : BaseViewModel
  18. {
  19. #region Constants
  20. private const int ASSISTANT_DRIVER_SOURCE = 4;
  21. #endregion Constants
  22. #region Fields
  23. public int seconds = 180;
  24. private string timerSeconds = "3:00";
  25. private string bookingId = "";
  26. public string pickUpAddress = "";
  27. public string dropUpAddress = "";
  28. private string errorMessage = "";
  29. private bool isProcessing = true;
  30. private bool isBookingConfirmed = false;
  31. public bool isBookingUnavailable = false;
  32. public bool isFutureBooking = false;
  33. private bool isBookingConfirmedAndOnDemand = false;
  34. #endregion
  35. #region Properties
  36. public string TimerSeconds
  37. {
  38. get => timerSeconds;
  39. set
  40. {
  41. SetProperty(ref timerSeconds, value);
  42. }
  43. }
  44. public string ErrorMessage
  45. {
  46. get => errorMessage;
  47. set
  48. {
  49. SetProperty(ref errorMessage, value);
  50. }
  51. }
  52. [Obsolete]
  53. public string BookingId
  54. {
  55. get => bookingId;
  56. set
  57. {
  58. SetProperty(ref bookingId, value);
  59. Processing(value);
  60. }
  61. }
  62. public string PickUpAddress
  63. {
  64. get => pickUpAddress;
  65. set
  66. {
  67. SetProperty(ref pickUpAddress, value);
  68. }
  69. }
  70. public string DropUpAddress
  71. {
  72. get => dropUpAddress;
  73. set
  74. {
  75. SetProperty(ref dropUpAddress, value);
  76. }
  77. }
  78. public bool IsProcessing
  79. {
  80. get => isProcessing;
  81. set => SetProperty(ref isProcessing, value);
  82. }
  83. public bool IsBookingConfirmed
  84. {
  85. get => isBookingConfirmed;
  86. set => SetProperty(ref isBookingConfirmed, value);
  87. }
  88. public bool IsBookingUnavailable
  89. {
  90. get => isBookingUnavailable;
  91. set => SetProperty(ref isBookingUnavailable, value);
  92. }
  93. public bool IsFutureBooking
  94. {
  95. get => isFutureBooking;
  96. set => SetProperty(ref isFutureBooking, value);
  97. }
  98. public bool IsBookingConfirmedAndOnDemand
  99. {
  100. get => isBookingConfirmedAndOnDemand;
  101. set => SetProperty(ref isBookingConfirmedAndOnDemand, value);
  102. }
  103. #endregion
  104. #region Constructor
  105. public AcceptBookingViewModel()
  106. {
  107. Title = "Processing";
  108. }
  109. #endregion
  110. #region Methods
  111. [Obsolete]
  112. private async void Processing(string booking_Id)
  113. {
  114. string rydoAccessToken = Preferences.Get(EftposLoginResponse.RYDO_ACCESS_TOKEN, "");
  115. Guid driverId = Guid.Parse(Preferences.Get(LoginResponseDto.USER_CODE, ""));
  116. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  117. AcceptDeclineBookingRequest acceptBookingRequest = new AcceptDeclineBookingRequest();
  118. var location = await Geolocation.GetLastKnownLocationAsync();
  119. acceptBookingRequest.DriverId = driverId;
  120. acceptBookingRequest.DriverSource = ASSISTANT_DRIVER_SOURCE;
  121. acceptBookingRequest.DriverLatitude = location.Latitude;
  122. acceptBookingRequest.DriverLongitude = location.Longitude;
  123. var res = await gmCabsDriverService.AcceptBooking(acceptBookingRequest, rydoAccessToken, booking_Id);
  124. if (res.StatusCode == (int)HttpStatusCode.OK)
  125. {
  126. Title = "Booking Confirmed";
  127. IsProcessing = false;
  128. IsBookingConfirmed = true;
  129. if (!IsFutureBooking)
  130. {
  131. IsBookingConfirmedAndOnDemand = true;
  132. Device.StartTimer(TimeSpan.FromSeconds(1), () =>
  133. {
  134. if (seconds > 0)
  135. {
  136. --seconds;
  137. TimerSeconds = seconds / 60 + ":" + (seconds % 60 <= 9 ? "0" + seconds % 60 : "" + seconds % 60);
  138. return true;
  139. }
  140. else
  141. {
  142. return false;
  143. }
  144. });
  145. }
  146. else
  147. {
  148. IsBookingConfirmedAndOnDemand = false;
  149. }
  150. }
  151. else
  152. {
  153. Title = "Booking Unavailable";
  154. ErrorMessage = res.Message;
  155. IsProcessing = false;
  156. IsBookingConfirmed = false;
  157. IsBookingUnavailable = true;
  158. }
  159. }
  160. #endregion
  161. }
  162. }