Example #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);
            }
        }
        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);
        }
Example #3
0
        public IEnumerable <PageModuleDisplayModelMapperOutput> Map(IEnumerable <PageModuleDisplayModelMapperInput <DocumentDataModel> > inputs, WorkFlowStatusQuery workflowStatus)
        {
            var documents = _queryExecutor.GetByIdRange <DocumentAssetRenderDetails>(inputs.Select(i => i.DataModel.DocumentAssetId));

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

                var output = new DocumentDisplayModel();
                if (document != null)
                {
                    output.Description = document.Description;
                    output.Title       = document.Title;
                    output.Url         = _documentAssetRouteLibrary.DocumentAsset(document);
                }

                yield return(input.CreateOutput(output));
            }
        }