public IActionResult Register(UserViewModel user) { System.Console.WriteLine("start"); if (ModelState.IsValid) { System.Console.WriteLine("valid"); string UserEmail = user.email; User LookupUser = _context.users.SingleOrDefault(login => login.email == UserEmail); if (LookupUser == null) { PasswordHasher <UserViewModel> Hasher = new PasswordHasher <UserViewModel>(); user.password = Hasher.HashPassword(user, user.password); System.Console.WriteLine("length is {0}", user.password.Length); User NewUser = new User { firstname = user.firstname, lastname = user.lastname, email = user.email, password = user.password, created_at = DateTime.Now, updated_at = DateTime.Now }; _context.Add(NewUser); _context.SaveChanges(); NewUser = _context.users.SingleOrDefault(login => login.email == UserEmail); HttpContext.Session.SetInt32("userid", NewUser.userid); HttpContext.Session.SetString("email", NewUser.email); System.Console.WriteLine("Iz guud!"); return(RedirectToAction("Plan", "Wedding")); // return RedirectToAction("Success"); } else { ModelState.AddModelError("email", "This Email is already registered."); ViewBag.errors = ModelState.Values; return(View("~/Views/User/LogReg.cshtml", user)); } } else { System.Console.WriteLine("Iz nah guud."); return(View("~/Views/User/LogReg.cshtml", user)); } }
public IActionResult SetPlan(WeddingViewModel plan) { if (ModelState.IsValid) { System.Console.WriteLine("wed1: {0}", plan.wedder1); System.Console.WriteLine("wed2: {0}", plan.wedder2); System.Console.WriteLine("date: {0}", plan.date); System.Console.WriteLine("address: {0}", plan.address); if (plan.date > DateTime.Now) { Wedding NewWedding = new Wedding { wedder1 = plan.wedder1, wedder2 = plan.wedder2, date = plan.date, address = plan.address, created_at = DateTime.Now, updated_at = DateTime.Now }; _context.Add(NewWedding); _context.SaveChanges(); return(RedirectToAction("Success", "User")); } else { ModelState.AddModelError("date", "Date must be in the future"); ViewBag.errors = ModelState.Values; return(View("~/Views/Wedding/Plan.cshtml", plan)); } } else { System.Console.WriteLine("Iz nah guud."); return(View("~/Views/Wedding/Plan.cshtml", plan)); } }