public IActionResult success() { if (UserSession == null) { return(RedirectToAction("Index")); } User user = DbContext.Users.FirstOrDefault(q => q.UserId == UserSession); List <Hobby> allH = DbContext.Hobbies.Include(w => w.CreatedJOINs).Include(q => q.Creator).ToList(); successModel model = new successModel(); model.userLogged = user; model.allH = allH; return(View(model)); }
public IActionResult wall() { if (HttpContext.Session.GetInt32("userId") == null) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { int uid = (int)HttpContext.Session.GetInt32("userId"); User user = dbContext.Users.FirstOrDefault(q => q.UserId == uid); List <Post> allP = dbContext.Posts.Include(q => q.Creator).Include(v => v.Votes).OrderByDescending(q => q.Votes.Count).ToList(); successModel model = new successModel(); model.userLogged = user; model.allP = allP; return(View(model)); } return(View()); }
public IActionResult newPost(successModel newPost) { if (HttpContext.Session.GetInt32("userId") == null) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { newPost.post.UserId = (int)HttpContext.Session.GetInt32("userId"); dbContext.Add(newPost.post); dbContext.SaveChanges(); return(RedirectToAction("wall")); } User user = dbContext.Users.FirstOrDefault(q => q.UserId == (int)HttpContext.Session.GetInt32("userId")); ViewBag.user = user; TempData["errors"] = "Post must be more than 5 characters."; return(RedirectToAction("wall")); }