예제 #1
0
        /// <summary>
        /// Gets all gift cards
        /// </summary>
        /// <param name="purchasedWithOrderId">Associated order ID; null to load all records</param>
        /// <param name="createdFromUtc">Created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Created date to (UTC); null to load all records</param>
        /// <param name="isGiftCardActivated">Value indicating whether gift card is activated; null to load all records</param>
        /// <param name="giftCardCouponCode">Gift card coupon code; nullto load all records</param>
        /// <param name="recipientName">Recipient name; null to load all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>Gift cards</returns>
        public virtual async Task <IPagedList <GiftCard> > GetAllGiftCards(string purchasedWithOrderItemId = "",
                                                                           DateTime?createdFromUtc         = null, DateTime?createdToUtc     = null,
                                                                           bool?isGiftCardActivated        = null, string giftCardCouponCode = null,
                                                                           string recipientName            = null,
                                                                           int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var model = new GetGiftCardQuery()
            {
                CreatedFromUtc           = createdFromUtc,
                CreatedToUtc             = createdToUtc,
                GiftCardCouponCode       = giftCardCouponCode,
                IsGiftCardActivated      = isGiftCardActivated,
                PageIndex                = pageIndex,
                PageSize                 = pageSize,
                PurchasedWithOrderItemId = purchasedWithOrderItemId,
                RecipientName            = recipientName
            };

            var query = await _mediator.Send(model);

            return(await PagedList <GiftCard> .Create(query, pageIndex, pageSize));
        }
예제 #2
0
        public Task <IMongoQueryable <GiftCard> > Handle(GetGiftCardQuery request, CancellationToken cancellationToken)
        {
            var query = _giftCardRepository.Table;

            if (!string.IsNullOrEmpty(request.GiftCardId))
            {
                query = query.Where(gc => gc.Id == request.GiftCardId);
            }

            if (!string.IsNullOrEmpty(request.PurchasedWithOrderItemId))
            {
                query = query.Where(gc => gc.PurchasedWithOrderItem.Id == request.PurchasedWithOrderItemId);
            }

            if (request.CreatedFromUtc.HasValue)
            {
                query = query.Where(gc => request.CreatedFromUtc.Value <= gc.CreatedOnUtc);
            }
            if (request.CreatedToUtc.HasValue)
            {
                query = query.Where(gc => request.CreatedToUtc.Value >= gc.CreatedOnUtc);
            }
            if (request.IsGiftCardActivated.HasValue)
            {
                query = query.Where(gc => gc.IsGiftCardActivated == request.IsGiftCardActivated.Value);
            }
            if (!string.IsNullOrEmpty(request.GiftCardCouponCode))
            {
                query = query.Where(gc => gc.GiftCardCouponCode == request.GiftCardCouponCode.ToLowerInvariant());
            }
            if (!string.IsNullOrWhiteSpace(request.RecipientName))
            {
                query = query.Where(c => c.RecipientName.Contains(request.RecipientName));
            }
            query = query.OrderByDescending(gc => gc.CreatedOnUtc);

            return(Task.FromResult(query));
        }