/// <summary> /// Prepare gift card search model /// </summary> /// <param name="searchModel">Gift card search model</param> /// <returns>Gift card search model</returns> public virtual GiftCardSearchModel PrepareGiftCardSearchModel(GiftCardSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare "activated" filter (0 - all; 1 - activated only; 2 - deactivated only) searchModel.ActivatedList.Add(new SelectListItem { Value = "0", Text = _localizationService.GetResource("Admin.GiftCards.List.Activated.All") }); searchModel.ActivatedList.Add(new SelectListItem { Value = "1", Text = _localizationService.GetResource("Admin.GiftCards.List.Activated.ActivatedOnly") }); searchModel.ActivatedList.Add(new SelectListItem { Value = "2", Text = _localizationService.GetResource("Admin.GiftCards.List.Activated.DeactivatedOnly") }); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
public virtual IActionResult GiftCardList(GiftCardSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageGiftCards)) { return(AccessDeniedKendoGridJson()); } //prepare model var model = _giftCardModelFactory.PrepareGiftCardListModel(searchModel); return(Json(model)); }
public virtual async Task <IActionResult> GiftCardList(GiftCardSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageGiftCards)) { return(await AccessDeniedDataTablesJson()); } //prepare model var model = await _giftCardModelFactory.PrepareGiftCardListModelAsync(searchModel); return(Json(model)); }
/// <summary> /// Prepare paged gift card list model /// </summary> /// <param name="searchModel">Gift card search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the gift card list model /// </returns> public virtual async Task <GiftCardListModel> PrepareGiftCardListModelAsync(GiftCardSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter gift cards var isActivatedOnly = searchModel.ActivatedId == 0 ? null : searchModel.ActivatedId == 1 ? true : (bool?)false; //get gift cards var giftCards = await _giftCardService.GetAllGiftCardsAsync(isGiftCardActivated : isActivatedOnly, giftCardCouponCode : searchModel.CouponCode, recipientName : searchModel.RecipientName, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare list model var model = await new GiftCardListModel().PrepareToGridAsync(searchModel, giftCards, () => { return(giftCards.SelectAwait(async giftCard => { //fill in model values from the entity var giftCardModel = giftCard.ToModel <GiftCardModel>(); //convert dates to the user time giftCardModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(giftCard.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) var giftAmount = await _giftCardService.GetGiftCardRemainingAmountAsync(giftCard); giftCardModel.RemainingAmountStr = await _priceFormatter.FormatPriceAsync(giftAmount, true, false); giftCardModel.AmountStr = await _priceFormatter.FormatPriceAsync(giftCard.Amount, true, false); return giftCardModel; })); }); return(model); }
/// <summary> /// Prepare paged gift card list model /// </summary> /// <param name="searchModel">Gift card search model</param> /// <returns>Gift card list model</returns> public virtual GiftCardListModel PrepareGiftCardListModel(GiftCardSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get parameters to filter gift cards var isActivatedOnly = searchModel.ActivatedId == 0 ? null : searchModel.ActivatedId == 1 ? true : (bool?)false; //get gift cards var giftCards = _giftCardService.GetAllGiftCards(isGiftCardActivated: isActivatedOnly, giftCardCouponCode: searchModel.CouponCode, recipientName: searchModel.RecipientName, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare list model var model = new GiftCardListModel { Data = giftCards.Select(giftCard => { //fill in model values from the entity var giftCardModel = giftCard.ToModel(); //convert dates to the user time giftCardModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) giftCardModel.RemainingAmountStr = _priceFormatter.FormatPrice(giftCard.GetGiftCardRemainingAmount(), true, false); giftCardModel.AmountStr = _priceFormatter.FormatPrice(giftCard.Amount, true, false); return(giftCardModel); }), Total = giftCards.TotalCount }; return(model); }