/// <summary> /// Old action for routing files without update timestamps and therefore /// not permanently cacheable. /// </summary> public async Task <ActionResult> File_OldPath(int assetId, string fileName, string extension) { var file = await GetDocumentAssetFile(assetId); if (file == null) { return(FileAssetNotFound("File not found")); } var url = _documentAssetRouteLibrary.DocumentAsset(file); return(RedirectPermanent(url)); }
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); }
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)); } }
/// <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); }
/// <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); }
/// <summary> /// Simple but less efficient way of getting a document url if you only know /// the id. Use the overload accepting an IDocumentAssetRenderable if possible to save a /// potential db query if the asset isn't cached. /// </summary> /// <param name="documentAssetId">Id of the document asset to get the url for</param> public string DocumentAsset(int?documentAssetId) { return(_documentAssetRouteLibrary.DocumentAsset(documentAssetId)); }
/// <summary> /// Gets the url for a document asset that displays the docment in the /// browser using the "inline" content disposition. /// </summary> /// <param name="asset">asset to get the url for.</param> public string DocumentAsset(IDocumentAssetRenderable asset) { return(_documentAssetRouteLibrary.DocumentAsset(asset)); }