public async Task <EntityResponse <Product> > Handle(GetProductsListQuery request, CancellationToken cancellationToken) { var response = new EntityResponse <Product> () { ReponseName = nameof(GetProductsListQuery), Content = new List <Product> () { } }; var entities = await _productRepository.GetAllAsync(); _mapper.Map <List <Product> > (entities); if (entities == null) { response.Status = ResponseType.Warning; response.Message = $"No {nameof(Product)}s were found."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Product)}s get successfully."; response.Content.AddRange(entities); } return(response); }
public async Task <ActionResult <EntityResponse <Product> > > GetProducts() { var query = new GetProductsListQuery(); var result = await _mediator.Send(query); return(Ok(result)); }
public async Task <IActionResult> GetProductsAsync([FromQuery] SearchContract searchContract) { if (searchContract == null) { return(Error("Invalid Input")); } else if (searchContract.PageNumber < 1) { return(Error("Invalid Page Number")); } else if (searchContract.PageSize < 1) { return(Error("Invalid Page Size")); } _logger.LogInformation("GetproductsAsync Called."); var query = new GetProductsListQuery { SearchContract = searchContract }; var list = await _messages.Dispatch(query).ConfigureAwait(false); return(Ok(list)); }
public async Task <List <ProductModel> > Handle(GetProductsListQuery request, CancellationToken cancellationToken) { return(await _dbContext.Products .Include(x => x.Seller) .Include(x => x.Brand) .Include(x => x.Category) .ProjectTo <ProductModel>(_mapper.ConfigurationProvider) .ToListAsync(cancellationToken)); }
public async Task GetList() { var query = new GetProductsListQuery(); var response = new ListResponseModel <ProductDto>(query, 100, new List <ProductDto>()); _mockMediator.Setup(x => x.Send(query, It.IsAny <CancellationToken>())) .ReturnsAsync(response); var result = await _sut.GetList(query); Assert.IsAssignableFrom <OkObjectResult>(result.Result); Assert.AreEqual(response, ((OkObjectResult)result.Result).Value); }
public async Task <List <ProductDTO> > Handle(GetProductsListQuery request, CancellationToken cancellationToken) { List <ProductDTO> productDTOs = new List <ProductDTO>(); var result = dbContext.Products.ToList(); if (result != null && result.Count() > 0) { ProductDTO temp; foreach (var prod in result) { temp = new ProductDTO() { ProductId = prod.ProductId, ProductName = prod.ProductName, ProductDesc = prod.ProductDesc, Price = prod.Price }; productDTOs.Add(temp); } } return(productDTOs); }
public async Task <IActionResult> GetProductsList([FromQuery] GetProductsListQuery productsListQuery) { var queryResult = await _mediator.Send(productsListQuery); return(Ok(queryResult)); }
protected async Task <PaginatedItems <ProductViewModel> > GetProductsAsync() { var getProducts = new GetProductsListQuery(); return(await Mediator.Send(getProducts)); }