public IBlogPost Select() { var serviceContext = BlogDependencies.GetServiceContext(); var query = serviceContext.CreateQuery("adx_blogpost") .Where(post => post.GetAttributeValue <Guid>("adx_blogpostid") == BlogPostReference.Id); if (!Security.UserHasAuthorPermission) { query = query.Where(post => post.GetAttributeValue <bool?>("adx_published") == true); } var entity = query.FirstOrDefault(); if (entity == null) { return(null); } var securityProvider = BlogDependencies.GetSecurityProvider(); if (!securityProvider.TryAssert(serviceContext, entity, CrmEntityRight.Read)) { return(null); } var urlProvider = BlogDependencies.GetUrlProvider(); var tagPathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies); return(new BlogPostFactory(serviceContext, urlProvider, BlogDependencies.GetWebsite(), tagPathGenerator).Create(new [] { entity }).FirstOrDefault()); }
public IEnumerable <IBlogPostWeightedTag> SelectWeightedTags(int weights) { var serviceContext = BlogDependencies.GetServiceContext(); var infos = serviceContext.FetchBlogPostTagCounts(Blog.Id) .Select(c => new BlogPostTagInfo(c.Item1, c.Item2)); var tagCloudData = new TagCloudData(weights, TagInfo.TagComparer, infos); var archivePathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies); return(tagCloudData.Select(e => new BlogPostWeightedTag(e.Name, archivePathGenerator.GetTagPath(e.Name, Blog), e.TaggedItemCount, e.Weight))); }
public IEnumerable <IBlogArchiveMonth> SelectArchiveMonths() { var serviceContext = BlogDependencies.GetServiceContext(); var counts = serviceContext.FetchBlogPostCountsGroupedByMonth(Blog.Id); var archivePathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies); return(counts.Select(c => { var month = new DateTime(c.Item1, c.Item2, 1, 0, 0, 0, DateTimeKind.Utc); return new BlogArchiveMonth(month, c.Item3, archivePathGenerator.GetMonthPath(month, Blog)); }).OrderByDescending(e => e.Month)); }
public IEnumerable <IBlogPost> SelectPosts(int startRowIndex, int maximumRows = -1) { if (startRowIndex < 0) { throw new ArgumentException("Value must be a positive integer.", "startRowIndex"); } if (maximumRows == 0) { return(new IBlogPost[] {}); } var serviceContext = Dependencies.GetServiceContext(); var query = serviceContext.CreateQuery("adx_blogpost") .Join(serviceContext.CreateQuery("adx_blogpost_tag"), post => post.GetAttributeValue <Guid>("adx_blogpostid"), postTag => postTag.GetAttributeValue <Guid>("adx_blogpostid"), (post, postTag) => new { Post = post, PostTag = postTag }) .Join(serviceContext.CreateQuery("adx_tag"), e => e.PostTag.GetAttributeValue <Guid>("adx_tagid"), tag => tag.GetAttributeValue <Guid>("adx_tagid"), (e, tag) => new { PostPostTag = e, Tag = tag }) .Where(e => e.Tag.GetAttributeValue <string>("adx_name") == Tag) .Where(e => e.PostPostTag.Post.GetAttributeValue <EntityReference>("adx_blogid") == Blog); if (!Security.UserHasAuthorPermission) { query = query.Where(e => e.PostPostTag.Post.GetAttributeValue <bool?>("adx_published") == true); } query = query.OrderByDescending(e => e.PostPostTag.Post.GetAttributeValue <DateTime?>("adx_date")); if (startRowIndex > 0) { query = query.Skip(startRowIndex); } if (maximumRows > 0) { query = query.Take(maximumRows); } var urlProvider = Dependencies.GetUrlProvider(); var tagPathGenerator = new BlogArchiveApplicationPathGenerator(Dependencies); return(new BlogPostFactory(serviceContext, urlProvider, Dependencies.GetWebsite(), tagPathGenerator).Create(query.Select(e => e.PostPostTag.Post))); }
public virtual IEnumerable <IBlogPost> SelectPosts(int startRowIndex, int maximumRows) { if (startRowIndex < 0) { throw new ArgumentException("Value must be a positive integer.", "startRowIndex"); } if (maximumRows == 0) { return(new IBlogPost[] { }); } var serviceContext = BlogDependencies.GetServiceContext(); var query = serviceContext.CreateQuery("adx_blogpost") .Where(post => post.GetAttributeValue <EntityReference>("adx_blogid") == Blog); if (!Security.UserHasAuthorPermission) { query = query.Where(post => post.GetAttributeValue <bool?>("adx_published") == true); } query = query.OrderByDescending(post => post.GetAttributeValue <DateTime?>("adx_date")); if (startRowIndex > 0) { query = query.Skip(startRowIndex); } if (maximumRows > 0) { query = query.Take(maximumRows); } var urlProvider = BlogDependencies.GetUrlProvider(); var tagPathGenerator = new BlogArchiveApplicationPathGenerator(BlogDependencies); return(new BlogPostFactory(serviceContext, urlProvider, BlogDependencies.GetWebsite(), tagPathGenerator).Create(query)); }