public Dto.Product GetBySku(int sku) { Model.Product product = ProductsRepo.GetBySku(sku); product.inventory.quantity = product.inventory.warehouses.Sum(a => a.quantity); product.isMarketable = product.inventory.quantity > 0; return(Mapper.Map <Dto.Product>(product)); }
public IActionResult Update(int sku, [FromBody] Dto.UpdateProduct productDto) { var product = ProductsRepo.GetBySku(sku); Mapper.Map(productDto, product); ProductsRepo.Update(product); return(Ok()); }
public IActionResult Create(int sku, [FromBody] Dto.UpdateProduct newProductDto) { var newProduct = new Model.Product(sku); Mapper.Map(newProductDto, newProduct); ProductsRepo.Create(newProduct); var createdProduct = ProductsRepo.GetBySku(sku); Logger.LogInformation("New product was created: {@product}", createdProduct); return(Created($"{sku}", Mapper.Map <Dto.Product>(createdProduct))); }