/// <summary> /// Gets all gift vouchers /// </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="isGiftVoucherActivated">Value indicating whether gift voucher is activated; null to load all records</param> /// <param name="giftVoucherCouponCode">Gift voucher 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 vouchers</returns> public virtual async Task <IPagedList <GiftVoucher> > GetAllGiftVouchers(string purchasedWithOrderItemId = "", DateTime?createdFromUtc = null, DateTime?createdToUtc = null, bool?isGiftVoucherActivated = null, string giftVoucherCouponCode = null, string recipientName = null, int pageIndex = 0, int pageSize = int.MaxValue) { var model = new GetGiftVoucherQuery() { CreatedFromUtc = createdFromUtc, CreatedToUtc = createdToUtc, Code = giftVoucherCouponCode, IsGiftVoucherActivated = isGiftVoucherActivated, PageIndex = pageIndex, PageSize = pageSize, PurchasedWithOrderItemId = purchasedWithOrderItemId, RecipientName = recipientName }; var query = await _mediator.Send(model); return(await PagedList <GiftVoucher> .Create(query, pageIndex, pageSize)); }
public Task <IQueryable <GiftVoucher> > Handle(GetGiftVoucherQuery request, CancellationToken cancellationToken) { var query = from p in _giftVoucherRepository.Table select p; if (!string.IsNullOrEmpty(request.GiftVoucherId)) { query = query.Where(gc => gc.Id == request.GiftVoucherId); } 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.IsGiftVoucherActivated.HasValue) { query = query.Where(gc => gc.IsGiftVoucherActivated == request.IsGiftVoucherActivated.Value); } if (!string.IsNullOrEmpty(request.Code)) { query = query.Where(gc => gc.Code == request.Code.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)); }