Beispiel #1
0
 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));
 }
Beispiel #2
0
        public IActionResult Update(int sku, [FromBody] Dto.UpdateProduct productDto)
        {
            var product = ProductsRepo.GetBySku(sku);

            Mapper.Map(productDto, product);
            ProductsRepo.Update(product);
            return(Ok());
        }
Beispiel #3
0
        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)));
        }