public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (db.Users.Any(user => user.Email == newUser.Email)) { ModelState.AddModelError("Email", "Email is already in use"); return(View("Index")); } PasswordHasher <User> hasher = new PasswordHasher <User>(); newUser.Password = hasher.HashPassword(newUser, newUser.Password); db.Add(newUser); db.SaveChanges(); HttpContext.Session.SetInt32("UserId", newUser.UserId); HttpContext.Session.SetString("FirstName", newUser.FirstName); HttpContext.Session.SetInt32("Balance", newUser.Balance); return(RedirectToAction("Dashboard", new { userId = newUser.UserId })); } else { return(View("Index")); } }