public async Task <IActionResult> Edit(MenumasterEditViewModel model) { if (ModelState.IsValid) { var storeobj = _menumasterservices.GetById(model.id); if (storeobj == null) { TempData["error"] = "Record Not Found"; return(NotFound()); } storeobj.id = model.id; storeobj.name = model.name; storeobj.productcuisineid = model.productcuisineid; 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 (Exception obj) { } } } var uploadDir = @"uploads/product"; 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(); storeobj.img = '/' + uploadDir + '/' + fileName; } await _menumasterservices.UpdateAsync(storeobj); TempData["success"] = "Record Update successfully"; return(RedirectToAction(nameof(test))); } else { return(View()); } }
public IActionResult Edit(int id) { ViewBag.productcuisine = _productcuisinemasterservices.GetAll().ToList(); var storeowner = _menumasterservices.GetById(id); if (storeowner == null) { return(NotFound()); } var model = new MenumasterEditViewModel() { id = storeowner.id, name = storeowner.name, productcuisineid = storeowner.productcuisineid }; return(View(model)); }