public async Task <IActionResult> Update(ProductUpdateVM updateVM, IFormFile file, string productImage) { if (!ModelState.IsValid) { return(View(updateVM)); } updateVM.ProductImage = productImage; if (file != null) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmssff") + extension; string path = Path.Combine(wwwRootPath + "/image/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(fileStream); } updateVM.ProductImage = fileName; } _command.Update(updateVM); return(RedirectToAction("List")); }
public async Task <IActionResult> Update(ProductsViewModel model) { await _product.Update(model); return(Redirect("/")); }