public async Task <IActionResult> Edit(CustomerRegistrationEditViewModel model) { if (ModelState.IsValid) { var customerobj = _CustomerRegistrationservices.GetById(model.id); if (customerobj == null) { return(NotFound()); } customerobj.id = model.id; customerobj.name = model.name; customerobj.address = model.address; // customerobj.mobileno1 = model.mobileno1; customerobj.mobileno2 = model.mobileno2; customerobj.emailid1 = model.emailid1; customerobj.latitude = model.latitude; customerobj.longitude = model.longitude; customerobj.password = model.password; customerobj.gender = model.gender; customerobj.DOB = model.DOB; if (model.profilephoto != null && model.profilephoto.Length > 0) { var uploadDir = @"uploads/customer"; var fileName = Path.GetFileNameWithoutExtension(model.profilephoto.FileName); var extesion = Path.GetExtension(model.profilephoto.FileName); var webRootPath = _hostingEnvironment.WebRootPath; if (customerobj.profilephoto != null) { var imagePath = webRootPath + customerobj.profilephoto.ToString().Replace("/", "\\"); if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } } fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); // await model.profilephoto.CopyToAsync(new FileStream(path, FileMode.Create)); FileStream fs = new FileStream(path, FileMode.Create); await model.profilephoto.CopyToAsync(fs); fs.Close(); customerobj.profilephoto = '/' + uploadDir + '/' + fileName; } await _CustomerRegistrationservices.UpdateAsync(customerobj); return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public IActionResult Edit(int id) { var objcustomer = _CustomerRegistrationservices.GetById(id); if (objcustomer == null) { return(NotFound()); } var model = new CustomerRegistrationEditViewModel { id = objcustomer.id , name = objcustomer.name // , profilephoto = objcustomer.profilephoto , address = objcustomer.address , mobileno1 = objcustomer.mobileno1 , mobileno2 = objcustomer.mobileno2 , emailid1 = objcustomer.emailid1 , latitude = objcustomer.latitude , longitude = objcustomer.longitude , password = objcustomer.password , gender = objcustomer.gender , DOB = objcustomer.DOB }; return(View(model)); }