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

using GMCabsDriverAssistant.Models;
using GMCabsDriverAssistant.Services;
using GMCabsDriverAssistant.Utils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GMCabsDriverAssistantSolution.ViewModels
{
public class CouponHistoryViewModel : BaseViewModel
{
#region Fields
private string loadingText = "Loading...";
private bool isLoading = true;
#endregion
#region Properties
public string LoadingText
{
get => loadingText;
set
{
SetProperty(ref loadingText, value);
}
}
public bool IsLoading
{
get => isLoading;
set
{
SetProperty(ref isLoading, value);
}
}
public ObservableCollection<CouponHistoryDto> CouponsHistory { get; }
#endregion
#region Constructor
public CouponHistoryViewModel()
{
Title = "Coupon History";
CouponsHistory = new ObservableCollection<CouponHistoryDto>();
GetCouponsHistory();
}
#endregion
#region Methods
private async void GetCouponsHistory()
{
string appToken = Preferences.Get(SecureStorageData.Token, "");
GMCabsDriverService gMCabsDriverService = new GMCabsDriverService();
CouponsHistory.Clear();
var coupons = await gMCabsDriverService.GetCouponsHistory(appToken);
if (coupons.Count > 0)
{
IsLoading = false; LoadingText = "";
}
else
{
IsLoading = true; LoadingText = "No coupons history available";
}
foreach (CouponHistoryDto coupon in coupons)
{
coupon.isRedemed = false;
if (coupon.RedeemedDate.HasValue)
{
coupon.CouponText = "Redeemed";
coupon.CouponBackgroundColor = "#2CC84E";
coupon.isRedemed = true;
}
else
{
coupon.CouponText = "EXPIRED";
coupon.CouponBackgroundColor = "#C82C2C";
}
CouponsHistory.Add(coupon);
}
}
#endregion
}
}