/// <summary> /// Prepare paged gift usage history card list model /// </summary> /// <param name="searchModel">Gift card usage history search model</param> /// <param name="giftCard">Gift card</param> /// <returns>Gift card usage history list model</returns> public virtual GiftCardUsageHistoryListModel PrepareGiftCardUsageHistoryListModel(GiftCardUsageHistorySearchModel searchModel, GiftCard giftCard) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (giftCard == null) { throw new ArgumentNullException(nameof(giftCard)); } //get gift card usage history var usageHistory = giftCard.GiftCardUsageHistory.OrderByDescending(historyEntry => historyEntry.CreatedOnUtc).ToList(); //prepare list model var model = new GiftCardUsageHistoryListModel { Data = usageHistory.PaginationByRequestModel(searchModel).Select(historyEntry => { //fill in model values from the entity var giftCardUsageHistoryModel = new GiftCardUsageHistoryModel { Id = historyEntry.Id, OrderId = historyEntry.UsedWithOrderId, CustomOrderNumber = historyEntry.UsedWithOrder.CustomOrderNumber }; //convert dates to the user time giftCardUsageHistoryModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(historyEntry.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) giftCardUsageHistoryModel.UsedValue = _priceFormatter.FormatPrice(historyEntry.UsedValue, true, false); return(giftCardUsageHistoryModel); }), Total = usageHistory.Count }; return(model); }
/// <summary> /// Prepare paged gift usage history card list model /// </summary> /// <param name="searchModel">Gift card usage history search model</param> /// <param name="giftCard">Gift card</param> /// <returns>Gift card usage history list model</returns> public virtual GiftCardUsageHistoryListModel PrepareGiftCardUsageHistoryListModel(GiftCardUsageHistorySearchModel searchModel, GiftCard giftCard) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (giftCard == null) { throw new ArgumentNullException(nameof(giftCard)); } //get gift card usage history var usageHistory = _giftCardService.GetGiftCardUsageHistory(giftCard) .OrderByDescending(historyEntry => historyEntry.CreatedOnUtc).ToList() .ToPagedList(searchModel); //prepare list model var model = new GiftCardUsageHistoryListModel().PrepareToGrid(searchModel, usageHistory, () => { return(usageHistory.Select(historyEntry => { //fill in model values from the entity var giftCardUsageHistoryModel = historyEntry.ToModel <GiftCardUsageHistoryModel>(); //convert dates to the user time giftCardUsageHistoryModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(historyEntry.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) giftCardUsageHistoryModel.OrderId = historyEntry.UsedWithOrderId; giftCardUsageHistoryModel.CustomOrderNumber = _orderService.GetOrderById(historyEntry.UsedWithOrderId)?.CustomOrderNumber; giftCardUsageHistoryModel.UsedValue = _priceFormatter.FormatPrice(historyEntry.UsedValue, true, false); return giftCardUsageHistoryModel; })); }); return(model); }