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); } }
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)); }
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 IEnumerable <IPermissionApplication> GetPermissions(GetDocumentAssetRenderDetailsByIdRangeQuery query) { yield return(new DocumentAssetReadPermission()); }
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); }
public IDomainRepositoryQueryContext <IDictionary <int, DocumentAssetRenderDetails> > AsRenderDetails() { var query = new GetDocumentAssetRenderDetailsByIdRangeQuery(_documentAssetIds); return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository)); }