public override dynamic GetViewContent(Raven.Client.IDocumentSession session) { return session.Query<BlogPost>().Where(x => x.CurrentState == BlogPost.State.Public).OrderByDescending(x => x.PublishedAt).Take(10).ToArray(); }
public List<BlogFeed> GetFeeds(Raven.Client.IDocumentSession session) { if (Id.IsNullOrWhiteSpace()) throw new ApplicationException("This blog must have an id before performing GetFeeds operations"); var feeds = session.Query<BlogFeed>().Where(x => x.BlogId == this.Id).OrderBy(x => x.Title).ToList(); return feeds; }
/// <summary> /// Fetch the posts related to this blog post by using paging. The posts are automatically sorted descending by post date published. /// </summary> /// <param name="session"></param> /// <param name="page"></param> /// <param name="pageSize"></param> public void LoadRss(Raven.Client.IDocumentSession session, int page = 1, int pageSize = 30) { RavenQueryStatistics stats; _posts = session.Query<BlogPost>() .Statistics(out stats) .Where(x => x.FeedId == this.Id) .OrderByDescending(x => x.DatePublished) .Take(pageSize) .Skip((page - 1) * pageSize) .ToList(); }
/// <summary> /// Find a BlogFeed by its url slug e.g. in the form of /f/{slug} such as /f/my-best-news /// </summary> /// <param name="session"></param> /// <param name="url"></param> /// <returns></returns> public static IQuerySetOne<BlogFeed> FindByUrl(Raven.Client.IDocumentSession session, string url) { var feed = session.Query<BlogFeed>().Where(x => x.Url == url.ToLower()).FirstOrDefault(); return new QuerySetOne<BlogFeed>(feed); }
/// <summary> /// Check if an existing BlogFeed by a given slug already exists. This is necessary because feed slug is universal per installation of this software. /// We could have scoped this by using blog name but it will make the link too long and nasty e.g http://hobieu.apphb.com/b/my-blog-name/f/feed-name /// </summary> /// <param name="session"></param> /// <param name="url"></param> /// <returns></returns> public static bool CheckIfUrlExist(Raven.Client.IDocumentSession session, string url) { return session.Query<BlogFeed>().Where(x => x.Url == url.ToLower()).Any(); }
public static IQuerySetOne<BlogPost> GetByUrl(Raven.Client.IDocumentSession session, string url) { var item = session.Query<BlogPost>().Where(x => x.Slug == url).FirstOrDefault(); return new QuerySetOne<BlogPost>(item); }
public static IQuerySetMany<BlogPost> GetByFeedId(Raven.Client.IDocumentSession session, string feedId, int page = 0, int pageSize = 30) { var items = session.Query<BlogPost>().Where(x => x.FeedId == feedId) .OrderByDescending(x => x.DatePublished) .Take(pageSize).Skip((page - 1) * pageSize).ToList(); return new QuerySetMany<BlogPost>(items); }