/// <summary> /// Executes the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A list of blog posts</returns> public BlogsGridViewModel <SiteSettingBlogPostViewModel> Execute(BlogsFilter request) { BlogPost alias = null; SiteSettingBlogPostViewModel modelAlias = null; var query = blogService.GetFilteredBlogPostsQuery(request); query = query .SelectList(select => select .Select(() => alias.Id).WithAlias(() => modelAlias.Id) .Select(() => alias.Title).WithAlias(() => modelAlias.Title) .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn) .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn) .Select(() => alias.ModifiedByUser).WithAlias(() => modelAlias.ModifiedByUser) .Select(() => alias.Status).WithAlias(() => modelAlias.Status) .Select(() => alias.Version).WithAlias(() => modelAlias.Version) .Select(() => alias.PageUrl).WithAlias(() => modelAlias.PageUrl)) .TransformUsing(Transformers.AliasToBean <SiteSettingBlogPostViewModel>()); var count = query.ToRowCountFutureValue(); var blogPosts = query.AddSortingAndPaging(request).Future <SiteSettingBlogPostViewModel>(); IEnumerable <LookupKeyValue> languagesFuture = configuration.EnableMultilanguage ? languageService.GetLanguagesLookupValues() : null; var model = new BlogsGridViewModel <SiteSettingBlogPostViewModel>(blogPosts.ToList(), request, count.Value); if (languagesFuture != null) { model.Languages = languagesFuture.ToList(); model.Languages.Insert(0, languageService.GetInvariantLanguageModel()); } return(model); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A list of blog posts</returns> public BlogsGridViewModel <SiteSettingBlogPostViewModel> Execute(BlogsFilter request) { BlogPost alias = null; // SiteSettingBlogPostViewModel modelAlias = null; BlogPost modelAlias = null; var query = blogService.GetFilteredBlogPostsQuery(request); query = query .SelectList(select => select .Select(() => alias.Id).WithAlias(() => modelAlias.Id) .Select(() => alias.Title).WithAlias(() => modelAlias.Title) .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn) .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn) .Select(() => alias.ModifiedByUser).WithAlias(() => modelAlias.ModifiedByUser) .Select(() => alias.Status).WithAlias(() => modelAlias.Status) .Select(() => alias.Version).WithAlias(() => modelAlias.Version) .Select(() => alias.PageUrl).WithAlias(() => modelAlias.PageUrl)) .TransformUsing(Transformers.AliasToBean <BlogPost>()); var count = query.ToRowCountFutureValue(); var blogPosts = query.AddSortingAndPaging(request).Future <BlogPost>(); IEnumerable <LookupKeyValue> languagesFuture = configuration.EnableMultilanguage ? languageService.GetLanguagesLookupValues() : null; var categoriesLookupList = categoryService.GetCategoriesLookupList(BlogPost.CategorizableItemKeyForBlogs); var blogsList = new List <SiteSettingBlogPostViewModel>(); foreach (var blogPost in blogPosts) { var blogModel = new SiteSettingBlogPostViewModel(); blogModel.Id = blogPost.Id; blogModel.Title = blogPost.Title; blogModel.CreatedOn = blogPost.CreatedOn.ToFormattedDateString(); blogModel.ModifiedOn = blogPost.ModifiedOn.ToFormattedDateString(); blogModel.ModifiedByUser = blogPost.ModifiedByUser; blogModel.Status = blogPost.Status; blogModel.Version = blogPost.Version; blogModel.PageUrl = blogPost.PageUrl; blogsList.Add(blogModel); } var model = new BlogsGridViewModel <SiteSettingBlogPostViewModel>(blogsList, request, count.Value) { CategoriesLookupList = categoriesLookupList }; if (languagesFuture != null) { model.Languages = languagesFuture.ToList(); model.Languages.Insert(0, languageService.GetInvariantLanguageModel()); } return(model); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A list of blog posts</returns> public BlogsGridViewModel <SiteSettingBlogPostViewModel> Execute(BlogsFilter request) { request.SetDefaultSortingOptions("Title"); BlogPost alias = null; SiteSettingBlogPostViewModel modelAlias = null; var query = UnitOfWork.Session .QueryOver(() => alias) .Where(() => !alias.IsDeleted && alias.Status != PageStatus.Preview); if (!request.IncludeArchived) { query = query.Where(() => !alias.IsArchived); } if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { var searchQuery = string.Format("%{0}%", request.SearchQuery); query = query.Where(Restrictions.InsensitiveLike(Projections.Property(() => alias.Title), searchQuery)); } if (request.CategoryId.HasValue) { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Category.Id), request.CategoryId.Value)); } if (request.LanguageId.HasValue) { if (request.LanguageId.Value.HasDefaultValue()) { query = query.Where(Restrictions.IsNull(Projections.Property(() => alias.Language.Id))); } else { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Language.Id), request.LanguageId.Value)); } } if (request.Tags != null) { foreach (var tagKeyValue in request.Tags) { var id = tagKeyValue.Key.ToGuidOrDefault(); query = query.WithSubquery.WhereExists(QueryOver.Of <PageTag>().Where(tag => tag.Tag.Id == id && tag.Page.Id == alias.Id).Select(tag => 1)); } } query = query .SelectList(select => select .Select(() => alias.Id).WithAlias(() => modelAlias.Id) .Select(() => alias.Title).WithAlias(() => modelAlias.Title) .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn) .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn) .Select(() => alias.ModifiedByUser).WithAlias(() => modelAlias.ModifiedByUser) .Select(() => alias.Status).WithAlias(() => modelAlias.PageStatus) .Select(() => alias.Version).WithAlias(() => modelAlias.Version) .Select(() => alias.PageUrl).WithAlias(() => modelAlias.PageUrl)) .TransformUsing(Transformers.AliasToBean <SiteSettingBlogPostViewModel>()); var count = query.ToRowCountFutureValue(); var blogPosts = query.AddSortingAndPaging(request).Future <SiteSettingBlogPostViewModel>(); IEnumerable <LookupKeyValue> languagesFuture = configuration.EnableMultilanguage ? languageService.GetLanguages() : null; var model = new BlogsGridViewModel <SiteSettingBlogPostViewModel>(blogPosts.ToList(), request, count.Value, categoryService.GetCategories()); if (languagesFuture != null) { model.Languages = languagesFuture.ToList(); model.Languages.Insert(0, languageService.GetInvariantLanguageModel()); } return(model); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A list of blog posts</returns> public BlogsGridViewModel <SiteSettingBlogPostViewModel> Execute(BlogsFilter request) { request.SetDefaultSortingOptions("Title"); BlogPost alias = null; SiteSettingBlogPostViewModel modelAlias = null; var query = UnitOfWork.Session .QueryOver(() => alias) .Where(() => !alias.IsDeleted && alias.Status != PageStatus.Preview); if (!request.IncludeArchived) { query = query.Where(() => !alias.IsArchived); } if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { var searchQuery = string.Format("%{0}%", request.SearchQuery); query = query.Where(Restrictions.InsensitiveLike(Projections.Property(() => alias.Title), searchQuery)); } if (request.CategoryId.HasValue) { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Category.Id), request.CategoryId.Value)); } if (request.LanguageId.HasValue) { if (request.LanguageId.Value.HasDefaultValue()) { query = query.Where(Restrictions.IsNull(Projections.Property(() => alias.Language.Id))); } else { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Language.Id), request.LanguageId.Value)); } } if (request.Tags != null) { foreach (var tagKeyValue in request.Tags) { var id = tagKeyValue.Key.ToGuidOrDefault(); query = query.WithSubquery.WhereExists(QueryOver.Of <PageTag>().Where(tag => tag.Tag.Id == id && tag.Page.Id == alias.Id).Select(tag => 1)); } } if (request.Status.HasValue) { if (request.Status.Value == PageStatusFilterType.OnlyPublished) { query = query.Where(() => alias.Status == PageStatus.Published); } else if (request.Status.Value == PageStatusFilterType.OnlyUnpublished) { query = query.Where(() => alias.Status != PageStatus.Published); } else if (request.Status.Value == PageStatusFilterType.ContainingUnpublishedContents) { const ContentStatus draft = ContentStatus.Draft; Root.Models.Content contentAlias = null; var subQuery = QueryOver.Of <PageContent>() .JoinAlias(p => p.Content, () => contentAlias) .Where(pageContent => pageContent.Page.Id == alias.Id) .And(() => contentAlias.Status == draft) .And(() => !contentAlias.IsDeleted) .Select(pageContent => 1); query = query.WithSubquery.WhereExists(subQuery); } } if (request.SeoStatus.HasValue) { var subQuery = QueryOver.Of <SitemapNode>() .Where(x => x.Page.Id == alias.Id || x.UrlHash == alias.PageUrlHash) .And(x => !x.IsDeleted) .JoinQueryOver(s => s.Sitemap) .And(x => !x.IsDeleted) .Select(s => 1); var hasSeoDisjunction = Restrictions.Disjunction() .Add(RestrictionsExtensions.IsNullOrWhiteSpace(Projections.Property(() => alias.MetaTitle))) .Add(RestrictionsExtensions.IsNullOrWhiteSpace(Projections.Property(() => alias.MetaKeywords))) .Add(RestrictionsExtensions.IsNullOrWhiteSpace(Projections.Property(() => alias.MetaDescription))) .Add(Subqueries.WhereNotExists(subQuery)); if (request.SeoStatus.Value == SeoStatusFilterType.HasSeo) { query = query.Where(Restrictions.Not(hasSeoDisjunction)); } else { query = query.Where(hasSeoDisjunction); } } query = query .SelectList(select => select .Select(() => alias.Id).WithAlias(() => modelAlias.Id) .Select(() => alias.Title).WithAlias(() => modelAlias.Title) .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn) .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn) .Select(() => alias.ModifiedByUser).WithAlias(() => modelAlias.ModifiedByUser) .Select(() => alias.Status).WithAlias(() => modelAlias.PageStatus) .Select(() => alias.Version).WithAlias(() => modelAlias.Version) .Select(() => alias.PageUrl).WithAlias(() => modelAlias.PageUrl)) .TransformUsing(Transformers.AliasToBean <SiteSettingBlogPostViewModel>()); var count = query.ToRowCountFutureValue(); var blogPosts = query.AddSortingAndPaging(request).Future <SiteSettingBlogPostViewModel>(); IEnumerable <LookupKeyValue> languagesFuture = configuration.EnableMultilanguage ? languageService.GetLanguages() : null; var model = new BlogsGridViewModel <SiteSettingBlogPostViewModel>(blogPosts.ToList(), request, count.Value, categoryService.GetCategories()); if (languagesFuture != null) { model.Languages = languagesFuture.ToList(); model.Languages.Insert(0, languageService.GetInvariantLanguageModel()); } return(model); }