示例#1
0
        private IEnumerable <SyndicationItem> GetItems(Uri baseUri)
        {
            UrlHelper urlHelper = new UrlHelper(Request.RequestContext);

            foreach (BlogPost post in RazorDb.Get <BlogPost>().Where(x => x.IsPublished()).OrderByDescending(x => x.Published).Take(10))
            {
                Uri             uri  = new Uri(baseUri, urlHelper.Action(post.GetAction()));
                SyndicationItem item = new SyndicationItem(
                    post.Title + (string.IsNullOrWhiteSpace(post.Lead) ? string.Empty : " - " + post.Lead),
                    post.RenderedContent, uri, uri.ToString(), post.Edited == default(DateTime) ? post.Published : post.Edited)
                {
                    PublishDate = post.Published
                };

                item.Authors.Add(new SyndicationPerson("", "Dave Glick", ""));
                yield return(item);
            }
        }
示例#2
0
 public virtual ActionResult Index()
 {
     return(View(new Index()
     {
         Posts = RazorDb.Get <BlogPost>()
                 .Where(x => x.IsPublished())
                 .OrderByDescending(x => x.Published)
                 .Take(3),
         Tags = RazorDb.Get <BlogPost>()
                .Where(x => x.Tags != null)
                .SelectMany(x => x.Tags)
                .Distinct()
                .Select(x => new KeyValuePair <string, int>(x, RazorDb.Get <BlogPost>()
                                                            .Where(y => y.Tags != null)
                                                            .Count(y => y.Tags.Contains(x))))
                .OrderByDescending(x => x.Value)
                .Take(10)
     }
                 ));
 }
示例#3
0
        public virtual ActionResult Tags(string tag)
        {
            IEnumerable <string> tags = RazorDb.Get <BlogPost>()
                                        .Where(x => x.Tags != null)
                                        .SelectMany(x => x.Tags)
                                        .Distinct();

            return(View(new Tags()
            {
                Tag = tags.FirstOrDefault(x => x.ToLowerInvariant().Replace(' ', '-') == tag),
                Posts = tag == null ? null : RazorDb.Get <BlogPost>()
                        .Where(x => x.IsPublished() && x.Tags != null && x.Tags.Any(y => y.ToLowerInvariant().Replace(' ', '-') == tag))
                        .OrderByDescending(x => x.Published),
                AllTags = tags
                          .Select(x => new KeyValuePair <string, int>(x, RazorDb.Get <BlogPost>()
                                                                      .Where(y => y.Tags != null)
                                                                      .Count(y => y.Tags.Contains(x))))
                          .OrderBy(x => x.Key)
            }
                        ));
        }
示例#4
0
        public virtual ActionResult Posts(string viewName)
        {
            if (viewName == null)
            {
                return(View("Archive",
                            RazorDb.Get <BlogPost>()
                            .Where(x => x.IsPublished())
                            .OrderByDescending(x => x.Published)
                            .GroupBy(x => x.Published == default(DateTime) ? Int32.MaxValue : x.Published.Year)
                            .OrderByDescending(x => x.Key)));
            }

            // Uncomment the publish check below to return a 404 if the post isn't published yet
            BlogPost post = RazorDb.Get <BlogPost>().FirstOrDefault(x => x.GetViewName() == viewName);

            if (post == null /* || !post.IsPublished() */)
            {
                throw new HttpException(404, "Page Not Found");
            }
            return(View("Posts/" + viewName, post));
        }