示例#1
0
        public async Task <IActionResult> OnPostUpdateProductAsync(Product updateProduct, IFormFile file)
        {
            Product product = await _productApi.GetProduct(updateProduct.Id);

            UpdateProductValues(product, updateProduct);
            if (file != null)
            {
                string path = "/images/product/" + file.FileName;
                using (var stream = new FileStream(_env.WebRootPath + path, FileMode.OpenOrCreate))
                {
                    await file.CopyToAsync(stream);
                }
                product.ImageFile = file.FileName;
            }
            if (await _productApi.UpdateProduct(product))
            {
                return(RedirectToPage());
            }
            ViewData["updateProductError"] = "Failed to update product";
            return(Page());
        }