Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Get([FromUri] SearchDocumentAssetSummariesQuery query)
        {
            if (query == null)
            {
                query = new SearchDocumentAssetSummariesQuery();
            }

            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(this, results));
        }
        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));
        }
        public async Task <IActionResult> Get(
            [FromQuery] SearchDocumentAssetSummariesQuery query,
            [FromQuery] GetDocumentAssetRenderDetailsByIdRangeQuery rangeQuery
            )
        {
            if (rangeQuery != null && rangeQuery.DocumentAssetIds != null)
            {
                var rangeResults = await _queryExecutor.ExecuteAsync(rangeQuery);

                return(_apiResponseHelper.SimpleQueryResponse(this, rangeResults.FilterAndOrderByKeys(rangeQuery.DocumentAssetIds)));
            }

            if (query == null)
            {
                query = new SearchDocumentAssetSummariesQuery();
            }

            var results = await _queryExecutor.ExecuteAsync(query);

            return(_apiResponseHelper.SimpleQueryResponse(this, results));
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> Get(
            [FromQuery] SearchDocumentAssetSummariesQuery query,
            [FromQuery] GetDocumentAssetRenderDetailsByIdRangeQuery rangeQuery
            )
        {
            if (rangeQuery != null && rangeQuery.DocumentAssetIds != null)
            {
                return(await _apiResponseHelper.RunWithResultAsync(async() =>
                {
                    return await _domainRepository
                    .WithQuery(rangeQuery)
                    .FilterAndOrderByKeys(rangeQuery.DocumentAssetIds)
                    .ExecuteAsync();
                }));
            }

            if (query == null)
            {
                query = new SearchDocumentAssetSummariesQuery();
            }
            ApiPagingHelper.SetDefaultBounds(query);

            return(await _apiResponseHelper.RunQueryAsync(query));
        }
 public IDomainRepositoryQueryContext <PagedQueryResult <DocumentAssetSummary> > AsSummaries(SearchDocumentAssetSummariesQuery query)
 {
     return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
 }
 public IEnumerable <IPermissionApplication> GetPermissions(SearchDocumentAssetSummariesQuery query)
 {
     yield return(new DocumentAssetReadPermission());
 }