public async Task <IActionResult> Create(DriverCreateViewModel model) { if (ModelState.IsValid) { var store = new driverRegistration { id = model.id , name = model.name // , profilephoto=model.profilephoto , mobileno = model.mobileno , emailid = model.emailid , password = model.password , gender = model.gender , latitude = "" , longitude = "" , deviceid = "" , createddate = model.createddate , isdeleted = false , isactive = false , biketype = model.biketype , manufacturename = model.manufacturename, modelname = model.modelname, modelyear = model.modelyear, vehicleplateno = model.vehicleplateno, accountno = model.accountno, banklocation = model.banklocation, bankname = model.bankname, ifsccode = model.ifsccode, status = model.status, bloodgroup = model.bloodgroup //drivinglicphoto = model.drivinglicphoto, //vehicleinsurancephoto = model.vehicleinsurancephoto, }; 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; 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(); store.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; 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(); store.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; 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(); store.vehicleinsurancephoto = '/' + uploadDir + '/' + fileName; } await _driverRegistrationServices.CreateAsync(store); TempData["success"] = "Record Save successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public IActionResult Create() { var model = new DriverCreateViewModel(); return(View(model)); }