public IActionResult CreatePost(LoadHomePageViewModel submittedPost) { if (submittedPost.post.user_id != LoggedUserId()) { return(RedirectToAction("LoadHomePage", "Load", new { load_id = submittedPost.post.load_id })); } Post postToAdd = submittedPost.post; _context.posts.Add(postToAdd); _context.SaveChanges(); return(RedirectToAction("LoadHomePage", "Load", new { load_id = submittedPost.post.load_id })); }
public IActionResult CreateComment(LoadHomePageViewModel submittedComment) { if (IsUserInSession() == false) { return(RedirectToAction("Index", "User")); } int _load_id = submittedComment.comment.load_id; if (ModelState.IsValid) { _context.comments.Add(submittedComment.comment); _context.SaveChanges(); return(RedirectToAction("LoadHomePage", "Load", new { load_id = _load_id })); } return(RedirectToAction("LoadHomePage", "Load", new { load_id = _load_id })); }
public IActionResult LoadHomePage(int load_id) { if (IsUserInSession() == false) { return(RedirectToAction("Index", "User")); } LoadHomePageViewModel viewModel = new LoadHomePageViewModel(); viewModel.user = _context.users .Where(p => p.user_id == LoggedUserId()) .FirstOrDefault(); viewModel.load = _context.loads .Where(p => p.load_id == load_id) .FirstOrDefault(); viewModel.manifests = _context.manifests .Where(p => p.load_id == load_id) .Include(p => p.user) .ToList(); viewModel.posts = _context.posts .Where(p => p.load_id == load_id) .Include(p => p.user) .OrderByDescending(p => p.created_at) .ToList(); viewModel.comments = _context.comments .Where(p => p.load_id == load_id) .Include(p => p.user) .OrderBy(p => p.created_at) .ToList(); return(View(viewModel)); }