Пример #1
0
        public DocumentAssetFile Execute(GetByIdQuery <DocumentAssetFile> query, IExecutionContext executionContext)
        {
            var dbResult = _dbContext
                           .DocumentAssets
                           .Where(f => f.DocumentAssetId == query.Id && !f.IsDeleted)
                           .Select(f => new {
                Extension   = f.FileExtension,
                ContentType = f.ContentType,
                FileName    = f.Title
            })
                           .SingleOrDefault();

            if (dbResult == null)
            {
                return(null);
            }
            var fileName = Path.ChangeExtension(query.Id.ToString(), dbResult.Extension);

            var result = new DocumentAssetFile();

            result.DocumentAssetId = query.Id;
            result.ContentType     = dbResult.ContentType;
            result.ContentStream   = _fileStoreService.Get(DocumentAssetConstants.FileContainerName, fileName);
            result.FileName        = FilePathHelper.CleanFileName(Path.ChangeExtension(dbResult.FileName, dbResult.Extension), fileName);

            if (result.ContentStream == null)
            {
                throw new FileNotFoundException("DocumentAsset file could not be found", fileName);
            }

            return(result);
        }
Пример #2
0
        public ImageAssetFile Execute(GetByIdQuery <ImageAssetFile> query, IExecutionContext executionContext)
        {
            var dbResult = _queryExecutor.GetById <ImageAssetRenderDetails>(query.Id);

            if (dbResult == null)
            {
                return(null);
            }
            var fileName = Path.ChangeExtension(query.Id.ToString(), dbResult.Extension);

            var result = Mapper.Map <ImageAssetFile>(dbResult);

            result.ContentStream = _fileStoreService.Get(ImageAssetConstants.FileContainerName, fileName);

            if (result.ContentStream == null)
            {
                throw new FileNotFoundException("Image asset file could not be found", fileName);
            }

            return(result);
        }