Example #1
0
        public async Task <IActionResult> Insert(ProductInsertDto product)
        {
            if (!ModelState.IsValid)
            {
                var errorMessage = new ErrorMessageViewModel("There was an error", "The model is invalid");

                return(RedirectToAction("Error", errorMessage));
            }

            var imageUrl = await _imageStorageService.UploadFile(product.Photo);

            var productModel = new ProductViewModel
            {
                Name  = product.Name,
                Photo = imageUrl,
                Price = product.Price
            };

            _productsServiceClient.InsertProduct(productModel);

            return(RedirectToAction("ProductList"));
        }