public IActionResult Register(RegisterViewModel NewUser) { User Validate = _Context.Users.Where(user => user.UserName == NewUser.UserName).SingleOrDefault(); if (ModelState.IsValid && Validate == null) { User ValidUser = new User() { UserName = NewUser.UserName, UserAlias = NewUser.UserAlias, Email = NewUser.Email, Password = NewUser.Password }; _Context.Users.Add(ValidUser); _Context.SaveChanges(); Validate = _Context.Users.Where(user => user.UserName == ValidUser.UserName).SingleOrDefault(); HttpContext.Session.SetInt32("UserId", (int)Validate.UserId); return(RedirectToAction("Index", "Home")); } else { ViewBag.valErrors = ModelState.Values; return(View("Index")); } }
public IActionResult PostNewIdea(string UserIdea) { if (HttpContext.Session.GetInt32("UserId") == null) { return(RedirectToAction("Index", "Login")); } if (UserIdea.Length > 0) { Idea NewIdea = new Idea() { UserId = (int)HttpContext.Session.GetInt32("UserId"), UserIdea = UserIdea }; _Context.Ideas.Add(NewIdea); _Context.SaveChanges(); } return(RedirectToAction("Index")); }