Пример #1
0
        public async Task <ServiceResponseWithPagination <List <mOrder> > > GetOrderWithFilterByDate(GetOrderDateFilterDTO orderFilter)
        {
            var Queryable = _dbContext.Orders.AsQueryable();

            if (orderFilter.DateFrom != null && orderFilter.DateTo != null)
            {
                //Queryable = Queryable.Where(x => x.DateOrder >= orderFilter.DateFrom.Value && x.DateOrder <= orderFilter.DateTo.Value.AddDays(1));
                Queryable = Queryable.Where(x => x.DateOrder >= orderFilter.DateFrom.Value.Date && x.DateOrder <= orderFilter.DateTo.Value.AddDays(1).Date);
            }

            if (!string.IsNullOrWhiteSpace(orderFilter.OrderingField))
            {
                try
                {
                    Queryable = Queryable.OrderBy($"{orderFilter.OrderingField} {(orderFilter.AscendingOrder ? "ascending" : "descending")}");
                }
                catch
                {
                    return(ResponseResultWithPagination.Failure <List <Models.Order.Order> >($"Could not order by field: {orderFilter.OrderingField}"));
                }

                ;
            }

            var paginationResult = await _httpcontext.HttpContext.InsertPaginationParametersInResponse(Queryable, orderFilter.RecordsPerPage, orderFilter.Page);

            var dto = await Queryable.Paginate(orderFilter).ToListAsync();

            return(ResponseResultWithPagination.Success(dto, paginationResult));
        }
 public async Task <IActionResult> GetOrderWithFilterByDate([FromQuery] GetOrderDateFilterDTO filter)
 {
     return(Ok(await _orderService.GetOrderWithFilterByDate(filter)));
 }