Beispiel #1
0
        public ActionResult Details(int year, int month, int day, string slug)
        {
            var post = CurrentSession
                .Query<Post>()
                .Include<Post>(x => x.CommentsId)
                .PublishedAt(year, month, day)
                .WithSlug(slug)
                .WhereIsPublicPost()
                .FirstOrDefault();

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

            //if (post.NotificationSend == false)
            //{
            //    _notification.SendAsync(post, new Uri(Url.AbsoluteAction("Details", "PostDetails", post.ToRouteData())));
            //    post.NotificationSend = true;
            //}

            var comments = CurrentSession.Load<PostComments>(post.CommentsId) ?? new PostComments();
            var vm = new PostViewModel
            {
                Post = Mapper.Map<PostViewModel.PostDetails>(post),
                Comments = Mapper.Map<IList<PostViewModel.Comment>>(comments.Comments),
                NextPost = CurrentSession.GetNextPrevPost(post, true),
                PreviousPost = CurrentSession.GetNextPrevPost(post, false),
                AreCommentsClosed = comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments),
            };

            vm.Post.Author = Mapper.Map<AuthorDetails>(BlogOwner);

            return View("Details", vm);
        }
        public static MvcHtmlString TrackbackRdf(this HtmlHelper html, PostViewModel post)
        {
            if (post.AreCommentsClosed || post.Post.IsCommentAllowed == false)
            {
                return MvcHtmlString.Create(string.Empty);
            }

            var urlHelper = new UrlHelper(html.ViewContext.RequestContext);
            var postUrl = urlHelper.AbsoluteAction("Details", "PostDetails", post.Post.ToRouteData());
            var trackbackUrl = urlHelper.AbsoluteAction("Trackback", "Services", new
            {
                id = post.Post.Id
            });

            return MvcHtmlString.Create(GetTrackbackRdf(postUrl, post.Post.Title, trackbackUrl));
        }