public ActionResult RegMotor(UserCarMotorModel UCM) { // Create User reference string tempPW = Convert.ToBase64String(System.Security.Cryptography.SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(UCM.Password))); User user = new User { FirstName = UCM.FirstName, LastName = UCM.LastName, UserName = UCM.UserName, Password = tempPW }; // Create car reference MotorBike motorBike = new MotorBike { MotorReg = UCM.MotorReg, MotorValue = UCM.MotorValue, ModeofUse = UCM.ModeofUse.ToString() }; if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); motorBike.UserId = user.UserId; db.MotorBikes.Add(motorBike); db.SaveChanges(); return(RedirectToAction("PleaseLogin", "User")); } return(View()); }
// Register a car, passed from main registration page public ActionResult RegCar() { // not catching the exeption??? // may try to add if statement if (Session["UserId"] == null) { return(RedirectToAction("Login")); } UserCarMotorModel userCarMotor = new UserCarMotorModel(); UserView userView = (UserView)TempData["user"]; userCarMotor.FirstName = userView.FirstName; userCarMotor.LastName = userView.LastName; userCarMotor.UserName = userView.UserName; userCarMotor.Password = userView.Password; return(View(userCarMotor)); }
public ActionResult RegCar(UserCarMotorModel UCM) { // Create User reference string tempPW = Convert.ToBase64String(System.Security.Cryptography.SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(UCM.Password))); User user = new User { FirstName = UCM.FirstName, LastName = UCM.LastName, UserName = UCM.UserName, Password = tempPW }; // Create car reference Car car = new Car { CarReg = UCM.CarReg, CarValue = UCM.CarValue, ModeofUse = UCM.ModeofUse.ToString() }; if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); car.UserId = user.UserId; db.Cars.Add(car); db.SaveChanges(); return(RedirectToAction("PleaseLogin", "User")); } // exeption handling here?... // Existing user regersting a new vehicle? return(View()); }