Exemplo n.º 1
0
		public ActionResult Display(string path)
		{
            _visitLogger.LogCurrentRequest();

			var post = _postRepository.GetPostAtUrl(path, p=>p.Author);
            var blog = _blogRepo.CurrentBlog();

            ViewBag.Analytics = blog.AnalyticsKey;
            ViewBag.Twitter = blog.Twitter;

			var prevPost = _postRepository.GetPostBefore(post);
			var nextPost = _postRepository.GetPostAfter(post);

			var md = new MarkdownDeep.Markdown();

            var model = new PostModel
            {
                Body = md.Transform(post.Body),
                Description = post.Description,
                Title = post.Title,
                Posted = post.Posted,
                CanonicalUrl = post.Canonical,
                Author = new PostAuthor
                {
                    GravatarUrl = post.Author.Email.GravitarUrlFromEmail(),
                    Name = String.Format("{0} {1}", post.Author.FirstName, post.Author.LastName),
                    GooglePlusProfileUrl = post.Author.GooglePlusProfileUrl
                },
                BlogConfig = new BlogConfig
                {
                    Disqus = blog.DisqusShortname,
                    BlogStyleId = blog.StyleId
                }
            };

            model.OtherPosts = new List<PartialPostForLinkModel>();
            model.OtherPosts.AddRange(_postRepository.PublishedPosts()
                .OrderBy(p => p.Posted)
                .Where(p => p.Posted > post.Posted)
                .Take(5)
                .OrderByDescending(p => p.Posted)
                .Select(p => new PartialPostForLinkModel { Title = p.Title, IsCurrentPost = false, Link = p.Path }));
            model.OtherPosts.Add(new PartialPostForLinkModel { Link = post.Path, IsCurrentPost = true, Title = post.Title });
            model.OtherPosts.AddRange(_postRepository.PublishedPosts()
                .OrderByDescending(p => p.Posted)
                .Where(p => p.Posted < post.Posted)
                .Take(5)
                .Select(p => new PartialPostForLinkModel { Title = p.Title, IsCurrentPost = false, Link = p.Path }));

			if(prevPost!= null)
			{
                model.PreviousPost = new PartialPostForLinkModel
                {
                    Date = prevPost.Posted,
				    Link = prevPost.Path,
				    Title = prevPost.Title
                };
			}

			if(nextPost!= null)
			{
                model.NextPost = new PartialPostForLinkModel
                {
                    Date = nextPost.Posted,
                    Link = nextPost.Path,
                    Title = nextPost.Title
                };
			}

			return View("Post", model);
		}
        private PostModel PostModel(string path, PostModel model = null)
        {
            if (model == null)
            {
                model = new PostModel();
            }

             var currentBlog = CurrentBlog;

            var post = _postRepository.GetPostAtUrl(currentBlog.Id, path, p => p.Author);

			var prevPost = _postRepository.GetPostBefore(post);
			var nextPost = _postRepository.GetPostAfter(post);

			var md = new MarkdownDeep.Markdown();
            
            model.Body = md.Transform(post.Body);
            model.Description = post.Description;
            model.Title = post.Title;
            model.Posted = post.Posted;
            model.CanonicalUrl = post.Canonical;
            model.Author = new PostAuthor
            {
                GravatarUrl = post.Author.Email.GravitarUrlFromEmail(),
                Name = post.Author.FullName(),
                GooglePlusProfileUrl = post.Author.GooglePlusProfileUrl
            };

            model.OtherPosts = new List<PartialPostForLinkModel>();
            model.OtherPosts.AddRange(_postRepository.PublishedPosts(currentBlog.Id)
                .OrderBy(p => p.Posted)
                .Where(p => p.Posted > post.Posted)
                .Take(5)
                .OrderByDescending(p => p.Posted)
                .Select(p => new PartialPostForLinkModel { Title = p.Title, IsCurrentPost = false, Link = p.Path }));
            model.OtherPosts.Add(new PartialPostForLinkModel { Link = post.Path, IsCurrentPost = true, Title = post.Title });
            model.OtherPosts.AddRange(_postRepository.PublishedPosts(currentBlog.Id)
                .OrderByDescending(p => p.Posted)
                .Where(p => p.Posted < post.Posted)
                .Take(5)
                .Select(p => new PartialPostForLinkModel { Title = p.Title, IsCurrentPost = false, Link = p.Path }));

			if(prevPost!= null)
			{
                model.PreviousPost = new PartialPostForLinkModel
                {
                    Date = prevPost.Posted,
				    Link = prevPost.Path,
				    Title = prevPost.Title
                };
			}

			if(nextPost!= null)
			{
                model.NextPost = new PartialPostForLinkModel
                {
                    Date = nextPost.Posted,
                    Link = nextPost.Path,
                    Title = nextPost.Title
                };
			}
            return model;
        }