public IActionResult Edit(int id) { var storeowner = _driverRegistrationServices.GetById(id); if (storeowner == null) { return(NotFound()); } var model = new DriverEditViewModel() { id = storeowner.id, name = storeowner.name, mobileno = storeowner.mobileno, emailid = storeowner.emailid, password = storeowner.password, gender = storeowner.gender, biketype = storeowner.biketype, manufacturename = storeowner.manufacturename, modelname = storeowner.modelname, modelyear = storeowner.modelyear, vehicleplateno = storeowner.vehicleplateno, accountno = storeowner.accountno, bankname = storeowner.bankname, banklocation = storeowner.banklocation, ifsccode = storeowner.ifsccode, status = storeowner.status, bloodgroup = storeowner.bloodgroup }; return(View(model)); }
public IActionResult Edit(DriverEditViewModel model) { Driver driver = driverRepository.GetDriverByID(model.DriverID); driver.Name = model.Name; driver.Age = model.Age; driverRepository.UpdateDriver(driver); driverRepository.Save(); return(RedirectToAction("Index")); }
public IActionResult Edit(int id) { Driver driver = driverRepository.GetDriverByID(id); DriverEditViewModel model = new DriverEditViewModel { Name = driver.Name, Age = driver.Age, DriverID = driver.DriverID }; return(View(model)); }
public async Task <IActionResult> Edit(DriverEditViewModel model) { if (ModelState.IsValid) { var storeobj = _driverRegistrationServices.GetById(model.id); if (storeobj == null) { return(NotFound()); } var chkduplicate = _driverRegistrationServices.GetAll().Where(x => x.mobileno == model.mobileno && x.id != model.id).FirstOrDefault(); if (chkduplicate != null) { ModelState.AddModelError("", "Duplicate Mobile No"); return(View(model)); } else { storeobj.id = model.id; storeobj.name = model.name; storeobj.mobileno = model.mobileno; storeobj.emailid = model.emailid; storeobj.password = model.password; storeobj.gender = model.gender; storeobj.manufacturename = model.manufacturename; storeobj.biketype = model.biketype; storeobj.modelname = model.modelname; storeobj.modelyear = model.modelyear; storeobj.vehicleplateno = model.vehicleplateno; storeobj.accountno = model.accountno; storeobj.banklocation = model.banklocation; storeobj.bankname = model.bankname; storeobj.ifsccode = model.ifsccode; storeobj.status = model.status; storeobj.bloodgroup = model.bloodgroup; if (model.profilephoto != null && model.profilephoto.Length > 0) { var uploadDir = @"uploads/driver/profilephoto"; var fileName = Path.GetFileNameWithoutExtension(model.profilephoto.FileName); var extesion = Path.GetExtension(model.profilephoto.FileName); var webRootPath = _hostingEnvironment.WebRootPath; if (storeobj.profilephoto != null) { var imagePath = webRootPath + storeobj.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(); storeobj.profilephoto = '/' + uploadDir + '/' + fileName; } if (model.drivinglicphoto != null && model.drivinglicphoto.Length > 0) { var uploadDir = @"uploads/driver/drivingLicence"; var fileName = Path.GetFileNameWithoutExtension(model.drivinglicphoto.FileName); var extesion = Path.GetExtension(model.drivinglicphoto.FileName); var webRootPath = _hostingEnvironment.WebRootPath; if (storeobj.drivinglicphoto != null) { var imagePath = webRootPath + storeobj.drivinglicphoto.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.drivinglicphoto.CopyToAsync(new FileStream(path, FileMode.Create)); FileStream fs = new FileStream(path, FileMode.Create); await model.drivinglicphoto.CopyToAsync(fs); fs.Close(); storeobj.drivinglicphoto = '/' + uploadDir + '/' + fileName; } if (model.vehicleinsurancephoto != null && model.vehicleinsurancephoto.Length > 0) { var uploadDir = @"uploads/driver/vehicleinsurancephoto"; var fileName = Path.GetFileNameWithoutExtension(model.vehicleinsurancephoto.FileName); var extesion = Path.GetExtension(model.vehicleinsurancephoto.FileName); var webRootPath = _hostingEnvironment.WebRootPath; if (storeobj.vehicleinsurancephoto != null) { var imagePath = webRootPath + storeobj.vehicleinsurancephoto.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.vehicleinsurancephoto.CopyToAsync(new FileStream(path, FileMode.Create)); FileStream fs = new FileStream(path, FileMode.Create); await model.vehicleinsurancephoto.CopyToAsync(fs); fs.Close(); storeobj.vehicleinsurancephoto = '/' + uploadDir + '/' + fileName; } await _driverRegistrationServices.UpdateAsync(storeobj); TempData["success"] = "Record Updated successfully"; return(RedirectToAction(nameof(Index))); } } else { return(View()); } }