public virtual IActionResult UsageHistoryList(GiftCardUsageHistorySearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedKendoGridJson()); } //try to get a gift card with the specified id var giftCard = _giftCardService.GetGiftCardById(searchModel.GiftCardId) ?? throw new ArgumentException("No gift card found with the specified id"); //prepare model var model = _giftCardModelFactory.PrepareGiftCardUsageHistoryListModel(searchModel, giftCard); return(Json(model)); }
public virtual async Task <IActionResult> UsageHistoryList(GiftCardUsageHistorySearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageGiftCards)) { return(await AccessDeniedDataTablesJson()); } //try to get a gift card with the specified id var giftCard = await _giftCardService.GetGiftCardByIdAsync(searchModel.GiftCardId) ?? throw new ArgumentException("No gift card found with the specified id"); //prepare model var model = await _giftCardModelFactory.PrepareGiftCardUsageHistoryListModelAsync(searchModel, giftCard); return(Json(model)); }
/// <summary> /// Prepare gift card usage history search model /// </summary> /// <param name="searchModel">Gift card usage history search model</param> /// <param name="giftCard">Gift card</param> /// <returns>Gift card usage history search model</returns> protected virtual GiftCardUsageHistorySearchModel PrepareGiftCardUsageHistorySearchModel(GiftCardUsageHistorySearchModel searchModel, GiftCard giftCard) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (giftCard == null) { throw new ArgumentNullException(nameof(giftCard)); } searchModel.GiftCardId = giftCard.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <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> /// A task that represents the asynchronous operation /// The task result contains the gift card usage history list model /// </returns> public virtual async Task <GiftCardUsageHistoryListModel> PrepareGiftCardUsageHistoryListModelAsync(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 = (await _giftCardService.GetGiftCardUsageHistoryAsync(giftCard)) .OrderByDescending(historyEntry => historyEntry.CreatedOnUtc).ToList() .ToPagedList(searchModel); //prepare list model var model = await new GiftCardUsageHistoryListModel().PrepareToGridAsync(searchModel, usageHistory, () => { return(usageHistory.SelectAwait(async historyEntry => { //fill in model values from the entity var giftCardUsageHistoryModel = historyEntry.ToModel <GiftCardUsageHistoryModel>(); //convert dates to the user time giftCardUsageHistoryModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(historyEntry.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) giftCardUsageHistoryModel.OrderId = historyEntry.UsedWithOrderId; giftCardUsageHistoryModel.CustomOrderNumber = (await _orderService.GetOrderByIdAsync(historyEntry.UsedWithOrderId))?.CustomOrderNumber; giftCardUsageHistoryModel.UsedValue = await _priceFormatter.FormatPriceAsync(historyEntry.UsedValue, true, false); return giftCardUsageHistoryModel; })); }); 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 = 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); }