public IActionResult AddProduct(AddProductParams product, string key) { if (!ModelState.IsValid) { throw new ArgumentNullException("product"); } else { _logger.LogInfo(key, LogEvents.AddItem, $"Attempt to add product."); int productId = _productFacade.AddProduct(key, product); if (!string.IsNullOrWhiteSpace(product.ImagePath)) { _logger.LogInfo(key, LogEvents.AddItem, $"Attempt to update product's new image path."); product.ImagePath = moveImage(product.ImagePath, product.GroupId, productId); UpdateProductParams productParams = new UpdateProductParams() { Id = productId, GroupId = product.GroupId, Name = product.Name, Description = product.Description, Price = product.Price, QuantityOnHand = product.QuantityOnHand, ImagePath = product.ImagePath }; _productFacade.UpdateProduct(key, productParams); _logger.LogInfo(key, LogEvents.AddItem, $"Product's new image path was updated successfully."); } _logger.LogInfo(key, LogEvents.AddItem, $"Product with Id: {productId} was added successfully."); return(Ok(productId)); } }
public IActionResult UpdateProduct(string key, UpdateProductParams product) { _logger.LogInfo(key, LogEvents.UpdateItem, $"Attempt to update product with Id: {product.Id}."); if (product.ImagePath.Contains("temp")) { product.ImagePath = moveImage(product.ImagePath, product.GroupId, product.Id); } Product newProduct = _productFacade.UpdateProduct(key, product); _logger.LogInfo(key, LogEvents.UpdateItem, $"Product with Id: {product.Id} was updated successfully."); return(Ok(newProduct)); }