Пример #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);
        }
Пример #3
0
        private ActionResult ValidateDocumentFileRequest(long fileStamp, string verificationToken, string fileName, DocumentAssetFile file, bool isDownload)
        {
            // additionally check that filestamp is not after the curent update date
            if (file == null || !IsFileStampValid(fileStamp, file.FileUpdateDate) || file.VerificationToken != verificationToken)
            {
                return(FileAssetNotFound("Document file not found"));
            }

            // if the title or filestamp is different, redirect to the correct url
            var sluggedFileName = SlugFormatter.ToSlug(file.FileName);

            if (sluggedFileName != fileName || fileStamp.ToString() != file.FileStamp)
            {
                var url = isDownload ? _documentAssetRouteLibrary.DocumentAssetDownload(file) : _documentAssetRouteLibrary.DocumentAsset(file);
                return(RedirectPermanent(url));
            }

            return(null);
        }
        /// <summary>
        /// Maps an EF DocumentAsset record from the db into a DocumentAssetDetails
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbDocument">DocumentAsset record from the database.</param>
        public DocumentAssetRenderDetails Map(DocumentAsset dbDocument)
        {
            if (dbDocument == null)
            {
                return(null);
            }

            var document = new DocumentAssetRenderDetails();

            document.DocumentAssetId   = dbDocument.DocumentAssetId;
            document.FileExtension     = dbDocument.FileExtension;
            document.FileName          = dbDocument.FileName;
            document.FileSizeInBytes   = dbDocument.FileSizeInBytes;
            document.Title             = dbDocument.Title;
            document.FileStamp         = AssetFileStampHelper.ToFileStamp(dbDocument.FileUpdateDate);
            document.Description       = dbDocument.Description;
            document.VerificationToken = dbDocument.VerificationToken;

            document.Url         = _documentAssetRouteLibrary.DocumentAsset(document);
            document.DownloadUrl = _documentAssetRouteLibrary.DocumentAssetDownload(document);

            return(document);
        }
Пример #5
0
        /// <summary>
        /// Used internally to map a model that inherits from DocumentAssetSummary.
        /// </summary>
        public DocumentAssetSummary Map <TModel>(TModel document, DocumentAsset dbDocument)
            where TModel : DocumentAssetSummary
        {
            document.AuditData         = _auditDataMapper.MapUpdateAuditData(dbDocument);
            document.DocumentAssetId   = dbDocument.DocumentAssetId;
            document.FileExtension     = dbDocument.FileExtension;
            document.FileName          = dbDocument.FileName;
            document.FileSizeInBytes   = dbDocument.FileSizeInBytes;
            document.FileStamp         = AssetFileStampHelper.ToFileStamp(dbDocument.FileUpdateDate);
            document.Title             = dbDocument.Title;
            document.VerificationToken = dbDocument.VerificationToken;

            document.Tags = dbDocument
                            .DocumentAssetTags
                            .Select(t => t.Tag.TagText)
                            .OrderBy(t => t)
                            .ToList();

            document.Url         = _documentAssetRouteLibrary.DocumentAsset(document);
            document.DownloadUrl = _documentAssetRouteLibrary.DocumentAssetDownload(document);

            return(document);
        }
Пример #6
0
 /// <summary>
 /// Gets the url for a document asset that is set to download using
 /// the "attachment" content disposition.
 /// </summary>
 /// <param name="asset">Document asset to get the url for.</param>
 public string DocumentAssetDownload(IDocumentAssetRenderable asset)
 {
     return(_documentAssetRouteLibrary.DocumentAssetDownload(asset));
 }