// GET: /<controller>/ public IActionResult DisplayFullBlogPost(int id) { var viewModel = new DisplayBlogPostViewModel(); var user = HttpContext.Session.GetInt32("userId"); //get the userId from the session var comment = HttpContext.Session.GetInt32("commentId"); //get the userId from the session viewModel.Blog = (from c in _blogContext.BlogPosts where c.BlogPostId == id select c).ToList(); viewModel.Users = (from c in _blogContext.Users where c.UserId == user select c).ToList(); viewModel.Photos = (from c in _blogContext.Photos where c.BlogPostId == id select c).ToList(); viewModel.Comments = (from c in _blogContext.Comments where c.BlogPostId == id select c).ToList(); return(View(viewModel)); }
public DisplayBlogPostViewModel GetSinglePost(int id) { var db = new DbEl(); if (db.BlogPosts.Any(i => i.BlogModelId == id)) { var post = db.BlogPosts.Find(id); var model = new DisplayBlogPostViewModel { Header = post.Header, HtmlContent = post.HtmlContent, Ingress = post.Ingress, ImagePath = post.ImagePath, Timestamp = post.Timestamp.ToString(), BlogModelId = post.BlogModelId }; return(model); } else { throw new Exception(); } }