コード例 #1
0
        public ActionResult RecentComments()
        {
            var commentsTuples = RavenSession.QueryForRecentComments(q => q.Take(5));

            var result = new List <RecentCommentViewModel>();

            foreach (var commentsTuple in commentsTuples)
            {
                var recentCommentViewModel = commentsTuple.Item1.MapTo <RecentCommentViewModel>();
                commentsTuple.Item2.MapPropertiesToInstance(recentCommentViewModel);
                result.Add(recentCommentViewModel);
            }
            return(View(result));
        }
コード例 #2
0
        public virtual ActionResult CommentsRss(int?id)
        {
            RavenQueryStatistics stats = null;
            var commentsTuples         = RavenSession.QueryForRecentComments(q =>
            {
                if (id != null)
                {
                    var postId = "posts/" + id;
                    q          = q.Where(x => x.PostId == postId);
                }
                return(q.Statistics(out stats).Take(30));
            });

            string responseETagHeader;

            if (CheckEtag(stats, out responseETagHeader))
            {
                return(HttpNotModified());
            }

            var rss = new XDocument(
                new XElement("rss",
                             new XAttribute("version", "2.0"),
                             new XElement("channel",
                                          new XElement("title", BlogConfig.Title),
                                          new XElement("link", Url.RelativeToAbsolute(Url.RouteUrl("homepage"))),
                                          new XElement("description", BlogConfig.MetaDescription ?? BlogConfig.Title),
                                          new XElement("copyright", String.Format("{0} (c) {1}", BlogConfig.Copyright, DateTime.Now.Year)),
                                          new XElement("ttl", "60"),
                                          from commentsTuple in commentsTuples
                                          let comment                                                        = commentsTuple.Item1
                                                                              let post                       = commentsTuple.Item2
                                                                                                    let link = Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title) }) + "#comment" + comment.Id
                                                                                                               select new XElement("item",
                                                                                                                                   new XElement("title", comment.Author + " commented on " + post.Title),
                                                                                                                                   new XElement("description", comment.Body),
                                                                                                                                   new XElement("link", link),
                                                                                                                                   new XElement("guid", link),
                                                                                                                                   new XElement("pubDate", comment.CreatedAt.ToString("R"))
                                                                                                                                   )
                                          )
                             )
                );

            return(Xml(rss, responseETagHeader));
        }