public Task <FindAllProductsResponse> Handle(FindAllProductsQuery request, CancellationToken cancellationToken)
        {
            try
            {
                var products = _context
                               .Set <Product>()
                               .Select(a => new ProductDTO
                {
                    ProductID   = a.Id,
                    Category    = a.Category,
                    Name        = a.Name,
                    Description = a.Description,
                    Price       = a.Price,
                    Quantity    = a.Quantity
                })
                               .AsQueryable();

                var response = PagedList <ProductDTO> .ToPagedList(products, request.CurrentPage, request.PageSize);

                return(Task.FromResult(new FindAllProductsResponse {
                    Response = response, Status = ResponseStatus.SUCCESS
                }));
            }
            catch (Exception e)
            {
                _logger.LogInformation(e.Message);
                return(Task.FromResult(new FindAllProductsResponse {
                    Status = ResponseStatus.ERROR
                }));
            }
        }
        public async Task <IEnumerable <ProductDto> > Handle(FindAllProductsQuery request, CancellationToken cancellationToken)
        {
            var result = await _productRepository.FindAllActive();

            return(result.Select(p => new ProductDto
            {
                Code = p.Code,
                Name = p.Name,
                Description = p.Description,
                Image = p.Image,
                MaxNumberOfInsured = p.MaxNumberOfInsured,
                Questions = p.Questions != null ? ProductAdapter.FromQuestionsToQuestionDtos(p.Questions.ToList()) : null,
                Covers = p.Covers.Any() ? ProductAdapter.FromCoversToCoverDtos(p.Covers.ToList()) : null
            }).ToList());
        }
        public ActionResult <IEnumerable <ProductDTO> > ListarProdutos()
        {
            try
            {
                var query = new FindAllProductsQuery();

                var listagem = _mediator.Send(query);

                if (listagem == null)
                {
                    return(NotFound());
                }

                return(Ok(listagem));
            }
            catch (Exception e)
            {
                _logger.LogInformation(e.Message);
                return(BadRequest(e.Message));
            }
        }
 /// <summary>
 ///  Handles FindAllProductsQuery request
 /// </summary>
 /// <param name="request">Request object</param>
 /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
 /// <returns>Product in store</returns>
 public async Task <IEnumerable <Product> > Handle(FindAllProductsQuery request, CancellationToken cancellationToken = default(CancellationToken))
 {
     //Call the Repository method to execute query.
     return(await _repository.GetAll());
 }
Esempio n. 5
0
 public async Task <IEnumerable <ProductDTO> > Handle(FindAllProductsQuery request, CancellationToken cancellationToken) =>
 this._mapper.Map <IEnumerable <ProductDTO> >(await this._productRepository.FindAllActive(cancellationToken));