Esempio n. 1
0
        public async Task <QueryResult <GoodsResponse> > Handle(GetGoodsQuery request, CancellationToken cancellationToken)
        {
            Expression <Func <Goods, bool> > searchFilter = x => (string.IsNullOrWhiteSpace(request.SearchQuery)) ||
                                                            x.Name.ToUpper().Contains(request.SearchQuery.ToUpper());

            var count = await _context.Goods.Where(searchFilter)
                        .CountAsync(cancellationToken).ConfigureAwait(false);

            if (count == 0)
            {
                return(new QueryResult <GoodsResponse>());
            }

            var goods = await _context.Goods.Where(searchFilter).AddPaging(request)
                        .ToListAsync(cancellationToken).ConfigureAwait(false);

            var response = goods.Select(x => x.ToResponse()).ToList();
            var paging   = CreatePaging(request, count);

            return(new QueryResult <GoodsResponse>(response, paging));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetGoodsByQuery([FromQuery] GetGoodsQuery query)
        {
            var result = await _mediator.Send(query);

            return(JsonResult(result));
        }