public IActionResult CreateUser(RegisUser user) { if (ModelState.IsValid) { PasswordHasher <RegisUser> Hasher = new PasswordHasher <RegisUser>(); user.Password = Hasher.HashPassword(user, user.Password); User NewUser = new User { Firstname = user.Firstname, Lastname = user.Lastname, Email = user.Email, Password = user.Password, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _context.Add(NewUser); _context.SaveChanges(); User justCreated = _context.Users.FirstOrDefault(User => user.Email == user.Email); HttpContext.Session.SetInt32("UserId", justCreated.UserId); HttpContext.Session.SetString("Firstname", justCreated.Firstname); return(RedirectToAction("ActivityList")); } return(View("Index")); }