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