/// <summary>
        /// Search return requests
        /// </summary>
        /// <param name="storeId">Store identifier; 0 to load all entries</param>
        /// <param name="customerId">Customer identifier; null to load all entries</param>
        /// <param name="orderItemId">Order item identifier; 0 to load all entries</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="rs">Return request status; null to load all entries</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>Return requests</returns>
        public virtual async Task <IPagedList <ReturnRequest> > SearchReturnRequests(string storeId     = "", string customerId      = "",
                                                                                     string orderItemId = "", ReturnRequestStatus?rs = null,
                                                                                     int pageIndex      = 0, int pageSize = int.MaxValue, DateTime?createdFromUtc = null, DateTime?createdToUtc = null)
        {
            var model = new GetReturnRequestQueryModel()
            {
                CreatedFromUtc = createdFromUtc,
                CreatedToUtc   = createdToUtc,
                PageIndex      = pageIndex,
                PageSize       = pageSize,
                CustomerId     = customerId,
                StoreId        = storeId,
                OrderItemId    = orderItemId,
                Rs             = rs,
            };

            var query = await _mediator.Send(model);

            return(await PagedList <ReturnRequest> .Create(query, pageIndex, pageSize));
        }
Пример #2
0
        public Task <IMongoQueryable <ReturnRequest> > Handle(GetReturnRequestQueryModel request, CancellationToken cancellationToken)
        {
            var query = _returnRequestRepository.Table;

            if (!string.IsNullOrEmpty(request.StoreId))
            {
                query = query.Where(rr => request.StoreId == rr.StoreId);
            }

            if (!string.IsNullOrEmpty(request.CustomerId))
            {
                query = query.Where(rr => request.CustomerId == rr.CustomerId);
            }

            if (request.Rs.HasValue)
            {
                var returnStatusId = (int)request.Rs.Value;
                query = query.Where(rr => rr.ReturnRequestStatusId == returnStatusId);
            }
            if (!string.IsNullOrEmpty(request.OrderItemId))
            {
                query = query.Where(rr => rr.ReturnRequestItems.Any(x => x.OrderItemId == request.OrderItemId));
            }

            if (request.CreatedFromUtc.HasValue)
            {
                query = query.Where(rr => request.CreatedFromUtc.Value <= rr.CreatedOnUtc);
            }

            if (request.CreatedToUtc.HasValue)
            {
                query = query.Where(rr => request.CreatedToUtc.Value >= rr.CreatedOnUtc);
            }

            query = query.OrderByDescending(rr => rr.CreatedOnUtc).ThenByDescending(rr => rr.Id);

            return(Task.FromResult(query));
        }