public IActionResult Register(User user) { if (ModelState.IsValid) { // check for uniqueness of email! if (dbContext.Users.Any(u => u.Email == user.Email)) { ModelState.AddModelError("Email", "Email already in use."); return(View("Index")); } // hash pw PasswordHasher <User> hasher = new PasswordHasher <User>(); string hashedPw = hasher.HashPassword(user, user.Password); user.Password = hashedPw; dbContext.Add(user); // once we save changes... // user.UserId will be updated! dbContext.SaveChanges(); HttpContext.Session.SetInt32("UserId", user.UserId); return(RedirectToAction("Index", "Post")); } return(View("Index")); }
public BoardMessage Add(BoardMessage message) { return(_context.Add(message).Entity); }