public async Task <ActionResult <ProductToReturnDto> > GetProduct(int id) { var spec = new ProductsWithTypeAndBrandSpecificaion(id); var product = await _repoProduct.GetEntityWithSpec(spec); // return new ProductToReturnDto // { // Id = product.Id, // Description = product.Description, // Name = product.Name, // Price = product.Price, // PictureUrl = product.PictureUrl, // ProductBrand = product.ProductBrand.Name, // ProductType = product.ProductType.Name // }; if (product != null) { return(Ok(mapper.Map <Product, ProductToReturnDto>(product))); } else { return(NotFound(new ApiResponse(404))); } }
public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProduct( [FromQuery] ProductSpecParams productParams) { var spec = new ProductsWithTypeAndBrandSpecificaion(productParams); var countSpec = new ProductWithFiltersForCountSpecification(productParams); var products = await _repoProduct.ListAsync(spec); var totalItem = await _repoProduct.CountAsync(countSpec); if (products != null) { var data = mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products); return(Ok(new Pagination <ProductToReturnDto>(productParams.Pageindex, productParams.Pagesize, totalItem, data))); // return products.Select(product => new ProductToReturnDto // { // Id = product.Id, // Description = product.Description, // Name = product.Name, // Price = product.Price, // PictureUrl = product.PictureUrl, // ProductBrand = product.ProductBrand.Name, // ProductType = product.ProductType.Name // }).ToList(); } else { return(NotFound()); } }