public async Task <IActionResult> Edit(productcuisineEditViewModel model) { if (ModelState.IsValid) { var storeobj = _productcuisinemasterservices.GetById(model.id); if (storeobj == null) { TempData["error"] = "Record Not Found"; return(NotFound()); } storeobj.id = model.id; storeobj.name = model.name; if (model.img != null && model.img.Length > 0) { if (storeobj.img != null && storeobj.img.Length > 0) { if (!string.IsNullOrEmpty(storeobj.img)) { try { var filePath1 = _hostingEnvironment.WebRootPath + storeobj.img.ToString().Replace("/", "\\"); if (System.IO.File.Exists(filePath1)) { System.IO.File.Delete(filePath1); } } catch { } } } var uploadDir = @"uploads/cuisine"; var fileName = Path.GetFileNameWithoutExtension(model.img.FileName); var extesion = Path.GetExtension(model.img.FileName); var webRootPath = _hostingEnvironment.WebRootPath; fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); FileStream fs = new FileStream(path, FileMode.Create); await model.img.CopyToAsync(fs); fs.Close(); // await model.img.CopyToAsync(new FileStream(path, FileMode.Create)); storeobj.img = '/' + uploadDir + '/' + fileName; } await _productcuisinemasterservices.UpdateAsync(storeobj); TempData["success"] = "Record Update successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public IActionResult Edit(int id) { var storeowner = _productcuisinemasterservices.GetById(id); if (storeowner == null) { return(NotFound()); } var model = new productcuisineEditViewModel() { id = storeowner.id, name = storeowner.name, }; return(View(model)); }