public ActionResult Details(int id) { var post = RavenSession .Include <Post>(x => x.CommentsId) .Load(id); if (post == null) { return(HttpNotFound()); } var comments = post.CommentsId == null ? DefaultPostComments() : (RavenSession.Load <PostComments>(post.CommentsId) ?? DefaultPostComments()); var vm = new AdminPostDetailsViewModel { Post = post.MapTo <AdminPostDetailsViewModel.PostDetails>(), Comments = comments.Comments .Concat(comments.Spam) .OrderBy(comment => comment.CreatedAt) .MapTo <AdminPostDetailsViewModel.Comment>(), NextPost = RavenSession.GetNextPrevPost(post, true), PreviousPost = RavenSession.GetNextPrevPost(post, false), AreCommentsClosed = comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments), }; return(View("Details", vm)); }
public ActionResult Details(int id, string slug) { var post = Session .Include <Post>(x => x.CommentsId) .Load(id); if (post == null) { return(HttpNotFound()); } var comments = Session.Load <PostComments>(post.CommentsId); var vm = new AdminPostDetailsViewModel { Post = post.MapTo <AdminPostDetailsViewModel.PostDetails>(), Comments = comments.Comments .Concat(comments.Spam) .OrderBy(comment => comment.CreatedAt) .MapTo <AdminPostDetailsViewModel.Comment>(), NextPost = Session.GetPostReference(x => x.PublishAt > post.PublishAt, desc: false), PreviousPost = Session.GetPostReference(x => x.PublishAt < post.PublishAt, desc: true), AreCommentsClosed = comments.AreCommentsClosed(post), }; if (vm.Post.Slug != slug) { return(RedirectToActionPermanent("Details", new { id, vm.Post.Slug })); } return(View("Details", vm)); }