public IActionResult RegistrationDriver() { DriverRegistrationInit dri = new DriverRegistrationInit(); using (var context = new MyTaxiDbContext()) { dri.CarColors = context.CarColors.ToList(); dri.CarClasses = context.CarClasses.ToList(); dri.JustInit = true; dri.Success = false; dri.isAuthorize = false; } return(View(dri)); }
public IActionResult RegistrationDriver(DriverRegistration driverRegistration) { if (driverRegistration != null) { using (var context = new MyTaxiDbContext()) { DriverRegistrationInit dri = new DriverRegistrationInit(); dri.CarClasses = context.CarClasses.ToList(); dri.CarColors = context.CarColors.ToList(); if (context.Users.Where(u => u.UserLogin == driverRegistration.login).Any()) { dri.Success = false; dri.JustInit = true; dri.isAuthorize = false; ViewData["ExistLogin"] = "******"; return(View(dri)); } context.Users.Add(new User { UserLogin = driverRegistration.login, UserPassword = driverRegistration.password, DriverSign = true }); context.Cars.Add(new Car { CarNumber = driverRegistration.carNumber, CarMark = driverRegistration.carMark, CarModl = driverRegistration.carModel, CarClassId = context.CarClasses.Where(cc => cc.CarClassName == driverRegistration.carClass) .FirstOrDefault()?.CarClassId, CarColorId = context.CarColors.Where(cc => cc.CarColorName == driverRegistration.carColor) .FirstOrDefault()?.CarColorId }); context.SaveChanges(); context.Drivers.Add(new Driver { DriverName = driverRegistration.driverName, DriverSurname = driverRegistration.driverSurname, DriverPatronymic = driverRegistration.driverPatronymic, DriverPhoneNumber = driverRegistration.driverPhone, UserID = context.Users.Local.Max(us => us.UserID), CarID = context.Cars.Local.Max(car => car.CarId) }); context.SaveChanges(); dri.Success = true; dri.JustInit = false; dri.isAuthorize = false; return(View(dri)); } } else { using (var context = new MyTaxiDbContext()) { DriverRegistrationInit dri = new DriverRegistrationInit(); dri.CarClasses = context.CarClasses.ToList(); dri.CarColors = context.CarColors.ToList(); dri.Success = false; dri.JustInit = true; dri.isAuthorize = false; return(View(dri)); } } }