public virtual IActionResult UsageHistoryList(DiscountUsageHistorySearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts)) return AccessDeniedKendoGridJson(); //try to get a discount with the specified id var discount = _discountService.GetDiscountById(searchModel.DiscountId) ?? throw new ArgumentException("No discount found with the specified id"); //prepare model var model = _discountModelFactory.PrepareDiscountUsageHistoryListModel(searchModel, discount); return Json(model); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> UsageHistoryList(DiscountUsageHistorySearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageDiscounts)) { return(await AccessDeniedDataTablesJson()); } //try to get a discount with the specified id var discount = await _discountService.GetDiscountByIdAsync(searchModel.DiscountId) ?? throw new ArgumentException("No discount found with the specified id"); //prepare model var model = await _discountModelFactory.PrepareDiscountUsageHistoryListModelAsync(searchModel, discount); return(Json(model)); }
/// <summary> /// Prepare discount usage history search model /// </summary> /// <param name="searchModel">Discount usage history search model</param> /// <param name="discount">Discount</param> /// <returns>Discount usage history search model</returns> protected virtual DiscountUsageHistorySearchModel PrepareDiscountUsageHistorySearchModel(DiscountUsageHistorySearchModel searchModel, Discount discount) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (discount == null) { throw new ArgumentNullException(nameof(discount)); } searchModel.DiscountId = discount.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare paged discount usage history list model /// </summary> /// <param name="searchModel">Discount usage history search model</param> /// <param name="discount">Discount</param> /// <returns>Discount usage history list model</returns> public virtual DiscountUsageHistoryListModel PrepareDiscountUsageHistoryListModel(DiscountUsageHistorySearchModel searchModel, Discount discount) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (discount == null) { throw new ArgumentNullException(nameof(discount)); } //get discount usage history var history = _discountService.GetAllDiscountUsageHistory(discountId: discount.Id, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare list model var model = new DiscountUsageHistoryListModel().PrepareToGrid(searchModel, history, () => { return(history.Select(historyEntry => { //fill in model values from the entity var discountUsageHistoryModel = historyEntry.ToModel <DiscountUsageHistoryModel>(); //convert dates to the user time discountUsageHistoryModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(historyEntry.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) var order = _orderService.GetOrderById(historyEntry.OrderId); if (order != null) { discountUsageHistoryModel.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false); discountUsageHistoryModel.CustomOrderNumber = order.CustomOrderNumber; } return discountUsageHistoryModel; })); }); return(model); }