public IActionResult Registration(ClientRegistration clientRegistration) { if (clientRegistration != null) { ClientRegistrationInit cri = new ClientRegistrationInit(); using (var context = new MyTaxiDbContext()) { if (context.Users.Where(u => u.UserLogin == clientRegistration.login).Any()) { cri.isAuthorize = false; cri.JustInit = true; cri.Success = false; ViewData["ExistLogin"] = "******"; return(View(cri)); } context.Users.Add(new User { UserLogin = clientRegistration.login, UserPassword = clientRegistration.password, DriverSign = false }); context.SaveChanges(); context.Clients.Add(new Client { ClientName = clientRegistration.userName, ClientSurname = clientRegistration.userSurname, ClientPatronymic = clientRegistration.userPatronymic, ClientPhoneNumber = clientRegistration.userPhone, UserID = context.Users.OrderBy(us => us.UserID).Last().UserID }); context.SaveChanges(); cri.Success = true; cri.JustInit = false; cri.isAuthorize = false; return(View(cri)); } } else { return(View()); } }
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)); } } }