public IActionResult AddThread(int CatId, Thread thread) { if (ModelState.IsValid) { int? UserId = HttpContext.Session.GetInt32("UserId"); Thread newThread = new Thread { Content = thread.Content, UserId = (int)UserId, CategoryId = CatId }; dbContext.Add(newThread); dbContext.SaveChanges(); return(RedirectToAction("Threads", new { id = CatId })); } return(View("NewThread")); }
public IActionResult Create(User user) { if (ModelState.IsValid) { PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); User newUSer = new User { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Password = user.Password }; dbContext.Add(newUSer); dbContext.SaveChanges(); var dbUser = dbContext.Users.FirstOrDefault(u => u.Email == user.Email); HttpContext.Session.SetInt32("UserId", dbUser.UserId); return(RedirectToAction("Success", "App", new { id = dbUser.UserId })); } return(View("Index")); }