public IActionResult GetProductsByBrandId(Guid brandId, [FromQuery] ProductSearchParams productSearchParams) { Brand brand = _repository.GetBrandById(brandId); if (brand == null) { return(NotFound()); } if (productSearchParams == null) { return(Ok(_mapper.Map <IEnumerable <ProductReadDto> >(_repository.GetProductsOfBrand(brandId)))); } var productsOfBrandQuery = _repository.GetProductsOfBrandWithParams(brandId, productSearchParams); if (productSearchParams.Fields == null) { return(Ok(_mapper.Map <IEnumerable <ProductReadDto> >(productsOfBrandQuery))); } List <ExpandoObject> list = new List <ExpandoObject>(); foreach (Product product in productsOfBrandQuery) { ProductReadDto pr = _mapper.Map <ProductReadDto>(product); list.Add(pr.ShapeData(productSearchParams.Fields)); } return(Ok(list)); }
public ActionResult UpdateProduct(Guid brandId, Guid productId, ProductUpdateDto productUpdateDto) { Brand brand = _repository.GetBrandById(brandId); if (brand == null) { return(NotFound()); } Product productOfBrand = _repository.GetProductById(productId); //put upserting if (productOfBrand == null) { Product product = _mapper.Map <Product>(productUpdateDto); product.Id = productId; _repository.AddProduct(brandId, product); _repository.SaveChanges(); ProductReadDto productRead = _mapper.Map <ProductReadDto>(product); return(CreatedAtRoute("GetProduct", new { brandId, productId = productRead.Id }, productRead)); } _mapper.Map(productUpdateDto, productOfBrand); _repository.UpdateProduct(productOfBrand); _repository.SaveChanges(); return(NoContent()); }
public ActionResult <ProductReadDto> CreateProduct(Guid brandId, ProductCreateDto productCreateDto) { Brand brand = _repository.GetBrandById(brandId); if (brand == null) { return(NotFound()); } Product createdProduct = _mapper.Map <Product>(productCreateDto); _repository.AddProduct(brandId, createdProduct); _repository.SaveChanges(); ProductReadDto productReadDto = _mapper.Map <ProductReadDto>(createdProduct); return(CreatedAtRoute("GetProduct", new { brandId, productId = productReadDto.Id }, productReadDto)); }
public Task SendBidUpdate(ProductReadDto Product) { return(Clients.All.SendAsync("ReceiveProduct", Product)); }