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.

126 lines
3.8 KiB

1 year ago
  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Services;
  3. using GMCabsDriverAssistantSolution.Models.Rydo;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace GMCabsDriverAssistantSolution.ViewModels
  11. {
  12. public class AcceptedFutureBookingsViewModel : BaseViewModel
  13. {
  14. #region Fields
  15. private string emptyViewMessage;
  16. private string startSuburb;
  17. private string endSuburb;
  18. private float distance;
  19. //private string formattedDistance;
  20. private bool isFutureBooking;
  21. private BookingDto _selectedBooking;
  22. #endregion
  23. #region Properties
  24. public string EmptyViewMessage
  25. {
  26. get => emptyViewMessage;
  27. set => SetProperty(ref emptyViewMessage, value);
  28. }
  29. public string StartSuburb
  30. {
  31. get => startSuburb;
  32. set => SetProperty(ref startSuburb, value);
  33. }
  34. public string EndSuburb
  35. {
  36. get => endSuburb;
  37. set => SetProperty(ref endSuburb, value);
  38. }
  39. public float Distance
  40. {
  41. get => distance;
  42. set => SetProperty(ref distance, value);
  43. }
  44. public bool IsFutureBooking
  45. {
  46. get => isFutureBooking;
  47. set => SetProperty(ref isFutureBooking, value);
  48. }
  49. public BookingDto SelectedBooking
  50. {
  51. get => _selectedBooking;
  52. set
  53. {
  54. SetProperty(ref _selectedBooking, value);
  55. OnFutureBookingSelected(value);
  56. }
  57. }
  58. public ObservableCollection<BookingDto> FutureBookings { get; }
  59. public Command<BookingDto> BookingTapped { get; }
  60. public Command OnRefreshClicked { get; }
  61. #endregion
  62. #region Constructor
  63. public AcceptedFutureBookingsViewModel()
  64. {
  65. Title = "Accepted Bookings";
  66. FutureBookings = new ObservableCollection<BookingDto>();
  67. OnRefreshClicked = new Command(async () => { await GetRydoFutureBookings(); });
  68. BookingTapped = new Command<BookingDto>(OnFutureBookingSelected);
  69. }
  70. #endregion
  71. #region Methods
  72. public void OnAppearing()
  73. {
  74. //IsBusy = true;
  75. SelectedBooking = null;
  76. Task.Run(async () =>
  77. {
  78. await GetRydoFutureBookings();
  79. });
  80. }
  81. private async Task GetRydoFutureBookings()
  82. {
  83. EmptyViewMessage = "Loading Future Bookings...";
  84. string rydoAccessToken = Preferences.Get(EftposLoginResponse.RYDO_ACCESS_TOKEN, "");
  85. Guid driverId = Guid.Parse(Preferences.Get(LoginResponseDto.USER_CODE, ""));
  86. GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
  87. FutureBookings.Clear();
  88. var bookings = await gmCabsDriverService.GetAcceptedFutureBookings(rydoAccessToken, driverId);
  89. var futureBookings = bookings.Where(b => b.FutureBooking == true);
  90. if (futureBookings.Count() > 0)
  91. {
  92. foreach (BookingDto booking in futureBookings)
  93. {
  94. FutureBookings.Add(booking);
  95. }
  96. }
  97. else
  98. {
  99. EmptyViewMessage = "No Future Bookings available";
  100. }
  101. }
  102. async void OnFutureBookingSelected(BookingDto booking)
  103. {
  104. if (booking == null) return;
  105. // await Shell.Current.GoToAsync($"{nameof(AcceptedFutureBookingDetailPage)}?{nameof(AcceptedFutureBookingDetailViewModel.BookingId)}={booking.BookingId:N}");
  106. }
  107. #endregion
  108. }
  109. }