public async Task <IActionResult> GiftVoucherList(DataSourceRequest command, GiftVoucherListModel model) { var(giftVoucherModels, totalCount) = await _giftVoucherViewModelService.PrepareGiftVoucherModel(model, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = giftVoucherModels.ToList(), Total = totalCount }; return(Json(gridModel)); }
public virtual GiftVoucherListModel PrepareGiftVoucherListModel() { var model = new GiftVoucherListModel(); model.ActivatedList.Add(new SelectListItem { Value = "", Text = _translationService.GetResource("Admin.GiftVouchers.List.Activated.All") }); model.ActivatedList.Add(new SelectListItem { Value = "1", Text = _translationService.GetResource("Admin.GiftVouchers.List.Activated.ActivatedOnly") }); model.ActivatedList.Add(new SelectListItem { Value = "2", Text = _translationService.GetResource("Admin.GiftVouchers.List.Activated.DeactivatedOnly") }); return(model); }
public virtual async Task <(IEnumerable <GiftVoucherModel> giftVoucherModels, int totalCount)> PrepareGiftVoucherModel(GiftVoucherListModel model, int pageIndex, int pageSize) { bool?isGiftVoucherActivated = null; if (model.ActivatedId == 1) { isGiftVoucherActivated = true; } else if (model.ActivatedId == 2) { isGiftVoucherActivated = false; } var giftVouchers = await _giftVoucherService.GetAllGiftVouchers(isGiftVoucherActivated : isGiftVoucherActivated, giftVoucherCouponCode : model.CouponCode, recipientName : model.RecipientName, pageIndex : pageIndex - 1, pageSize : pageSize); var giftvouchers = new List <GiftVoucherModel>(); foreach (var item in giftVouchers) { var gift = item.ToModel(_dateTimeService); var currency = await _currencyService.GetCurrencyByCode(item.CurrencyCode); if (currency == null) { currency = await _currencyService.GetPrimaryStoreCurrency(); } gift.RemainingAmountStr = _priceFormatter.FormatPrice(item.GetGiftVoucherRemainingAmount(), currency, _workContext.WorkingLanguage, true, false); gift.AmountStr = _priceFormatter.FormatPrice(item.Amount, currency, _workContext.WorkingLanguage, true, false); gift.CreatedOn = _dateTimeService.ConvertToUserTime(item.CreatedOnUtc, DateTimeKind.Utc); giftvouchers.Add(gift); } return(giftvouchers, giftVouchers.TotalCount); }