Exemplo n.º 1
0
        public async Task MapAsync(
            PageBlockTypeDisplayModelMapperContext <DocumentDataModel> context,
            PageBlockTypeDisplayModelMapperResult <DocumentDataModel> result
            )
        {
            var documentIds    = context.Items.SelectDistinctModelValuesWithoutEmpty(i => i.DocumentAssetId);
            var documentsQuery = new GetDocumentAssetRenderDetailsByIdRangeQuery(documentIds);
            var documents      = await _queryExecutor.ExecuteAsync(documentsQuery, context.ExecutionContext);

            foreach (var item in context.Items)
            {
                var document = documents.GetOrDefault(item.DataModel.DocumentAssetId);

                var displayModel = new DocumentDisplayModel();
                if (document != null)
                {
                    displayModel.Description = document.Description;
                    displayModel.Title       = document.Title;
                    if (item.DataModel.DownloadMode == DocumentDownloadMode.ForceDownload)
                    {
                        displayModel.Url = _documentAssetRouteLibrary.DocumentAssetDownload(document);
                    }
                    else
                    {
                        displayModel.Url = _documentAssetRouteLibrary.DocumentAsset(document);
                    }
                }

                result.Add(item, displayModel);
            }
        }
Exemplo n.º 2
0
 private IQueryable <DocumentAsset> QueryDb(GetDocumentAssetRenderDetailsByIdRangeQuery query)
 {
     return(_dbContext
            .DocumentAssets
            .AsNoTracking()
            .FilterByIds(query.DocumentAssetIds));
 }
        public async Task <IEnumerable <PageBlockTypeDisplayModelMapperOutput> > MapAsync(
            IReadOnlyCollection <PageBlockTypeDisplayModelMapperInput <DocumentDataModel> > inputCollection,
            PublishStatusQuery publishStatusQuery
            )
        {
            var documentIds    = inputCollection.SelectDistinctModelValuesWithoutEmpty(i => i.DocumentAssetId);
            var documentsQuery = new GetDocumentAssetRenderDetailsByIdRangeQuery(documentIds);
            var documents      = await _queryExecutor.ExecuteAsync(documentsQuery);

            var results = new List <PageBlockTypeDisplayModelMapperOutput>(inputCollection.Count);

            foreach (var input in inputCollection)
            {
                var document = documents.GetOrDefault(input.DataModel.DocumentAssetId);

                var output = new DocumentDisplayModel();
                if (document != null)
                {
                    output.Description = document.Description;
                    output.Title       = document.Title;
                    if (input.DataModel.DownloadMode == DocumentDownloadMode.ForceDownload)
                    {
                        output.Url = _documentAssetRouteLibrary.DocumentAssetDownload(document);
                    }
                    else
                    {
                        output.Url = _documentAssetRouteLibrary.DocumentAsset(document);
                    }
                }

                results.Add(input.CreateOutput(output));
            }

            return(results);
        }
        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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
 public IEnumerable <IPermissionApplication> GetPermissions(GetDocumentAssetRenderDetailsByIdRangeQuery query)
 {
     yield return(new DocumentAssetReadPermission());
 }
Exemplo n.º 7
0
        public async Task <IDictionary <int, DocumentAssetRenderDetails> > ExecuteAsync(GetDocumentAssetRenderDetailsByIdRangeQuery query, IExecutionContext executionContext)
        {
            var dbResults = await QueryDb(query).ToListAsync();

            var mappedResults = dbResults
                                .Select(_documentAssetRenderDetailsMapper.Map)
                                .ToDictionary(d => d.DocumentAssetId);

            return(mappedResults);
        }
Exemplo n.º 8
0
        public IDomainRepositoryQueryContext <IDictionary <int, DocumentAssetRenderDetails> > AsRenderDetails()
        {
            var query = new GetDocumentAssetRenderDetailsByIdRangeQuery(_documentAssetIds);

            return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
        }