/// <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); }