Exemplo n.º 1
0
		public ActionResult Details(int id)
		{
			var post = RavenSession
				.Include<Post>(x => x.CommentsId)
				.Load(id);

			if (post == null)
				return HttpNotFound();

			var comments = RavenSession.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 = 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),
                PreviousPost = Session.GetPostReference(x => x.PublishAt < post.PublishAt),
                AreCommentsClosed = comments.AreCommentsClosed(post),
            };

            if (vm.Post.Slug != slug)
                return RedirectToActionPermanent("Details", new { id, vm.Post.Slug });

            return View("Details", vm);
        }