Пример #1
0
        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));
            }
        }