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.

83 lines
2.4 KiB

1 year ago
  1. using GMCabsDriverAssistant.Models;
  2. using GMCabsDriverAssistant.Services;
  3. using GMCabsDriverAssistant.Utils;
  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 CouponHistoryViewModel : BaseViewModel
  13. {
  14. #region Fields
  15. private string loadingText = "Loading...";
  16. private bool isLoading = true;
  17. #endregion
  18. #region Properties
  19. public string LoadingText
  20. {
  21. get => loadingText;
  22. set
  23. {
  24. SetProperty(ref loadingText, value);
  25. }
  26. }
  27. public bool IsLoading
  28. {
  29. get => isLoading;
  30. set
  31. {
  32. SetProperty(ref isLoading, value);
  33. }
  34. }
  35. public ObservableCollection<CouponHistoryDto> CouponsHistory { get; }
  36. #endregion
  37. #region Constructor
  38. public CouponHistoryViewModel()
  39. {
  40. Title = "Coupon History";
  41. CouponsHistory = new ObservableCollection<CouponHistoryDto>();
  42. GetCouponsHistory();
  43. }
  44. #endregion
  45. #region Methods
  46. private async void GetCouponsHistory()
  47. {
  48. string appToken = Preferences.Get(SecureStorageData.Token, "");
  49. GMCabsDriverService gMCabsDriverService = new GMCabsDriverService();
  50. CouponsHistory.Clear();
  51. var coupons = await gMCabsDriverService.GetCouponsHistory(appToken);
  52. if (coupons.Count > 0)
  53. {
  54. IsLoading = false; LoadingText = "";
  55. }
  56. else
  57. {
  58. IsLoading = true; LoadingText = "No coupons history available";
  59. }
  60. foreach (CouponHistoryDto coupon in coupons)
  61. {
  62. coupon.isRedemed = false;
  63. if (coupon.RedeemedDate.HasValue)
  64. {
  65. coupon.CouponText = "Redeemed";
  66. coupon.CouponBackgroundColor = "#2CC84E";
  67. coupon.isRedemed = true;
  68. }
  69. else
  70. {
  71. coupon.CouponText = "EXPIRED";
  72. coupon.CouponBackgroundColor = "#C82C2C";
  73. }
  74. CouponsHistory.Add(coupon);
  75. }
  76. }
  77. #endregion
  78. }
  79. }