public async Task <PagedQueryResult <DocumentAssetSummary> > ExecuteAsync(SearchDocumentAssetSummariesQuery query, IExecutionContext executionContext)
        {
            IQueryable <DocumentAsset> dbQuery = _dbContext
                                                 .DocumentAssets
                                                 .AsNoTracking()
                                                 .Include(a => a.Creator)
                                                 .Include(a => a.Updater)
                                                 .Include(a => a.DocumentAssetTags)
                                                 .ThenInclude(a => a.Tag);

            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();

                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.DocumentAssetTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            // Filter multple extensions
            if (!string.IsNullOrEmpty(query.FileExtensions))
            {
                var fileExtensions = query.FileExtensions.Split(new char[] { '.', ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                dbQuery = dbQuery.Where(p => fileExtensions.Contains(p.FileExtension));
            }

            if (!string.IsNullOrWhiteSpace(query.FileExtension))
            {
                var formattedExtension = query.FileExtension.TrimStart('.');
                dbQuery = dbQuery.Where(p => p.FileExtension == formattedExtension);
            }

            var dbPagesResults = await dbQuery
                                 .OrderByDescending(p => p.CreateDate)
                                 .ToPagedResultAsync(query);

            var mappedResults = dbPagesResults
                                .Items
                                .Select(_documentAssetSummaryMapper.Map);

            return(dbPagesResults.ChangeType(mappedResults));
        }
Esempio n. 2
0
        public async Task <PagedQueryResult <ImageAssetSummary> > ExecuteAsync(SearchImageAssetSummariesQuery query, IExecutionContext executionContext)
        {
            var dbQuery = _dbContext
                          .ImageAssets
                          .AsNoTracking()
                          .Where(i => !i.IsDeleted);

            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();
                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.ImageAssetTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            // Filter Dimensions
            if (query.Height > 0)
            {
                dbQuery = dbQuery.Where(p => p.Height == query.Height);
            }
            else if (query.MinHeight > 0)
            {
                dbQuery = dbQuery.Where(p => p.Height >= query.MinHeight);
            }

            if (query.Width > 0)
            {
                dbQuery = dbQuery.Where(p => p.Width == query.Width);
            }
            else if (query.MinWidth > 0)
            {
                dbQuery = dbQuery.Where(p => p.Width >= query.MinWidth);
            }

            var results = await dbQuery
                          .OrderByDescending(p => p.CreateDate)
                          .ProjectTo <ImageAssetSummary>()
                          .ToPagedResultAsync(query);

            return(results);
        }
Esempio n. 3
0
 /// <summary>
 /// Updates a collection of entity tags with tags parsed from a user
 /// entered string.
 /// </summary>
 /// <typeparam name="TEntityTag">type of tags to update e.g. PageTag. You will need to mark up the Data class with IEntityTag</typeparam>
 /// <param name="existingTagCollection">Collection of existing tags to update (can be empty for a new entity)</param>
 /// <param name="unparsedTags">Unparsed tag text string e.g. Waffle, Dog, Bannana, "Danish Pastry"</param>
 /// <param name="executionContext">The execution context that captures the state of the command being executed.</param>
 public void UpdateTags <TEntityTag>(ICollection <TEntityTag> existingTagCollection, string unparsedTags, IExecutionContext executionContext) where TEntityTag : class, IEntityTag, new()
 {
     UpdateTags(existingTagCollection, TagParser.Split(unparsedTags), executionContext);
 }
        private IQueryable <Page> CreateQuery(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var dbQuery = _dbContext
                          .PagePublishStatusQueries
                          .AsNoTracking()
                          .Include(p => p.Page)
                          .ThenInclude(p => p.Creator)
                          .FilterByStatus(PublishStatusQuery.Latest, executionContext.ExecutionDate)
                          .FilterActive()
            ;

            // Filter by layout
            if (query.PageTemplateId > 0)
            {
                dbQuery = dbQuery.Where(v => v.PageVersion.PageTemplateId == query.PageTemplateId);
            }

            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();
                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.Page.PageTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            if (!string.IsNullOrWhiteSpace(query.Text))
            {
                var sluggedQuery = SlugFormatter.ToSlug(query.Text);
                var textQuery    = sluggedQuery.Replace("-", " ");

                dbQuery = dbQuery.Where(p =>
                                        (p.Page.UrlPath.Contains(sluggedQuery) || (p.Page.UrlPath == string.Empty && p.Page.PageDirectory.UrlPath.Contains(sluggedQuery))) ||
                                        p.PageVersion.Title.Contains(textQuery));
            }

            // Filter by workflow status (only draft and published are applicable
            if (query.PublishStatus == PublishStatus.Published)
            {
                dbQuery = dbQuery.Where(p => p.Page.PublishStatusCode == PublishStatusCode.Published);
            }
            else if (query.PublishStatus == PublishStatus.Unpublished)
            {
                // A page might be published, but also have a draft as the latest version
                dbQuery = dbQuery.Where(p => p.Page.PublishStatusCode == PublishStatusCode.Unpublished);
            }

            // Filter by locale
            if (query.LocaleId > 0)
            {
                dbQuery = dbQuery.FilterByLocaleId(query.LocaleId.Value);
            }

            // Filter by directory
            if (query.PageDirectoryId > 0)
            {
                dbQuery = dbQuery.FilterByDirectoryId(query.PageDirectoryId.Value);
            }

            // Filter by group
            if (query.PageGroupId > 0)
            {
                dbQuery = dbQuery.Where(p => p.Page.PageGroupItems.Any(i => i.PageGroupId == query.PageGroupId));
            }

            return(dbQuery
                   .SortBy(query.SortBy, query.SortDirection)
                   .Select(p => p.Page));
        }
        private IQueryable <PageSummary> CreateQuery(SearchPageSummariesQuery query)
        {
            var dbQuery = _dbContext
                          .Pages
                          .AsNoTracking()
                          .Where(p => !p.IsDeleted && p.WebDirectory.IsActive);


            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();
                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.PageTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            // Filter by workflow status (only draft and published are applicable
            if (query.WorkFlowStatus == WorkFlowStatus.Draft)
            {
                dbQuery = dbQuery.Where(p => p.PageVersions
                                        .OrderByDescending(v => v.CreateDate)
                                        .Where(v => !v.IsDeleted)
                                        .Take(1)
                                        .Any(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft));
            }
            else if (query.WorkFlowStatus == WorkFlowStatus.Published)
            {
                // A page might be published, but also have a draft as the latest version
                dbQuery = dbQuery.Where(p => p.PageVersions
                                        .Where(v => !v.IsDeleted)
                                        .Any(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Published));
            }

            // Filter by locale
            if (query.LocaleId > 0)
            {
                dbQuery = dbQuery.Where(p => p.LocaleId == query.LocaleId);
            }

            // Filter by directory
            if (query.WebDirectoryId > 0)
            {
                dbQuery = dbQuery.Where(p => p.WebDirectoryId == query.WebDirectoryId);
            }

            // Filter by layout
            if (query.PageTemplateId > 0)
            {
                dbQuery = dbQuery.Where(p => p.PageVersions
                                        .OrderByDescending(v => v.CreateDate)
                                        .Where(v => !v.IsDeleted)
                                        .Take(1)
                                        .Any(v => v.PageTemplateId == query.PageTemplateId));
            }

            // Filter by group
            if (query.PageGroupId > 0)
            {
                dbQuery = dbQuery.Where(p => p.PageGroupItems.Any(i => i.PageGroupId == query.PageGroupId));
            }
            return(dbQuery
                   .OrderByDescending(p => p.CreateDate)
                   .ProjectTo <PageSummary>());
        }
Esempio n. 6
0
        private IQueryable <PagePublishStatusQuery> CreateQuery(SearchPageSummariesQuery query, IExecutionContext executionContext)
        {
            var dbQuery = _dbContext
                          .PagePublishStatusQueries
                          .AsNoTracking()
                          .Include(p => p.Page)
                          .Include(p => p.Page.Creator)
                          .FilterByStatus(PublishStatusQuery.Latest, executionContext.ExecutionDate)
                          .FilterActive()
            ;

            // Filter by layout
            if (query.PageTemplateId > 0)
            {
                dbQuery = dbQuery.Where(v => v.PageVersion.PageTemplateId == query.PageTemplateId);
            }

            // Filter by tags
            if (!string.IsNullOrEmpty(query.Tags))
            {
                var tags = TagParser.Split(query.Tags).ToList();
                foreach (string tag in tags)
                {
                    // See http://stackoverflow.com/a/7288269/486434 for why this is copied into a new variable
                    string localTag = tag;

                    dbQuery = dbQuery.Where(p => p.Page.PageTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

            // Filter by workflow status (only draft and published are applicable
            if (query.PublishStatus == PublishStatus.Published)
            {
                dbQuery = dbQuery.Where(p => p.Page.PublishStatusCode == PublishStatusCode.Published);
            }
            else if (query.PublishStatus == PublishStatus.Unpublished)
            {
                // A page might be published, but also have a draft as the latest version
                dbQuery = dbQuery.Where(p => p.Page.PublishStatusCode == PublishStatusCode.Unpublished);
            }

            // Filter by locale
            if (query.LocaleId > 0)
            {
                dbQuery = dbQuery.Where(p => p.Page.LocaleId == query.LocaleId);
            }

            // Filter by directory
            if (query.PageDirectoryId > 0)
            {
                dbQuery = dbQuery.Where(p => p.Page.PageDirectoryId == query.PageDirectoryId);
            }

            // Filter by group
            if (query.PageGroupId > 0)
            {
                dbQuery = dbQuery.Where(p => p.Page.PageGroupItems.Any(i => i.PageGroupId == query.PageGroupId));
            }

            return(dbQuery.OrderByDescending(p => p.Page.CreateDate));
        }