public async Task <PagedQueryResult <ImageAssetSummary> > ExecuteAsync(SearchImageAssetSummariesQuery query, IExecutionContext executionContext)
        {
            IQueryable <ImageAsset> dbQuery = _dbContext
                                              .ImageAssets
                                              .AsNoTracking()
                                              .Include(i => i.Creator)
                                              .Include(i => i.Updater)
                                              .Include(i => i.ImageAssetTags)
                                              .ThenInclude(i => i.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.ImageAssetTags
                                            .Select(t => t.Tag.TagText)
                                            .Contains(localTag)
                                            );
                }
            }

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

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

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

            var mappedResults = dbPagedResults
                                .Items
                                .Select(_imageAssetSummaryMapper.Map)
                                .ToList();

            return(dbPagedResults.ChangeType(mappedResults));
        }
Example #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);
        }
 public IEnumerable <IPermissionApplication> GetPermissions(SearchImageAssetSummariesQuery query)
 {
     yield return(new ImageAssetReadPermission());
 }
Example #4
0
 public IContentRepositoryQueryContext <PagedQueryResult <ImageAssetSummary> > AsSummaries(SearchImageAssetSummariesQuery query)
 {
     return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }
Example #5
0
 public Task <PagedQueryResult <ImageAssetSummary> > SearchImageAssetSummariesAsync(SearchImageAssetSummariesQuery query, IExecutionContext executionContext = null)
 {
     return(_queryExecutor.ExecuteAsync(query, executionContext));
 }
Example #6
0
 public Task <PagedQueryResult <ImageAssetSummary> > AsSummariesAsync(SearchImageAssetSummariesQuery query)
 {
     return(ExtendableContentRepository.ExecuteQueryAsync(query));
 }