public async Task <ActionResult <ProductToReturnDto> > GetProduct(int id) { var spec = new ProductsWithProductTypeAndBrandsSpecification(id); var product = await _productRepository.GetEntityWithSpec(spec); return(_mapper.Map <Product, ProductToReturnDto>(product)); }
public async Task <ActionResult <Pagination <ProductToReturnResponse> > > GetProducts([FromQuery] ProductSpecParams productSpecParams) { var spec = new ProductsWithProductTypeAndBrandsSpecification(productSpecParams); var countSpec = new ProductWithFiltersForCountSpecification(productSpecParams); var totalItems = await _productRepository.CountAsync(countSpec); var products = await _productRepository.ListAsync(spec); var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnResponse> >(products); return(Ok(new Pagination <ProductToReturnResponse>(productSpecParams.PageIndex, productSpecParams.PageSize, totalItems, data))); }
[HttpGet("{id}")] //https://localhost:44306/api/products/3 public async Task <ActionResult <ProductToReturnResponse> > GetProduct(int id) { var spec = new ProductsWithProductTypeAndBrandsSpecification(id); var product = await _productRepository.GetEntityWithSpec(spec); /* * return new ProductToReturnResponse * { * Id = product.Id, * Name = product.Name, * Description = product.Description, * PictureUrl = product.PictureUrl, * Price = product.Price, * ProductBrand = product.ProductBrand != null ? product.ProductBrand.Name : string.Empty, * ProductType = product.ProductType != null ? product.ProductType.Name:string.Empty * }; */ return(_mapper.Map <Product, ProductToReturnResponse>(product)); }
public async Task <ActionResult <ProductToReturnDto> > GetProduct(int id) { var spec = new ProductsWithProductTypeAndBrandsSpecification(id); // return await _productRepository.GetEntityWithSpec(spec); var product = await _productRepository.GetEntityWithSpec(spec); //return new ProductToReturnDto //{ // Id = product.Id, // Name = product.Name, // Description = product.Description, // PictureUrl = product.PictureUrl, // Price = product.Price, // ProductBrand = product.ProductBrand != null ? product.ProductBrand.Name : string.Empty, // ProductType = product.ProductType != null ? product.ProductType.Name : string.Empty //}; return(_mapper.Map <Product, ProductToReturnDto>(product)); }