public async Task <UploadDigitalAssetResponse> Handle(UploadDigitalAssetRequest request)
            {
                NameValueCollection formData      = request.Provider.FormData;
                IList <HttpContent> files         = request.Provider.Files;
                List <DigitalAsset> digitalAssets = new List <DigitalAsset>();

                foreach (var file in files)
                {
                    var filename = new FileInfo(file.Headers.ContentDisposition.FileName.Trim(new char[] { '"' })
                                                .Replace("&", "and")).Name;
                    Stream stream = await file.ReadAsStreamAsync();

                    var bytes        = StreamHelper.ReadToEnd(stream);
                    var digitalAsset = new DigitalAsset();
                    digitalAsset.FileName    = filename;
                    digitalAsset.Bytes       = bytes;
                    digitalAsset.ContentType = System.Convert.ToString(file.Headers.ContentType);
                    _context.DigitalAssets.Add(digitalAsset);
                    digitalAssets.Add(digitalAsset);
                }

                await _context.SaveChangesAsync();

                _cache.Add(null, DigitalAssetCacheKeys.DigitalAssets);

                return(new UploadDigitalAssetResponse()
                {
                    DigitalAssets = digitalAssets.Select(x => DigitalAssetApiModel.FromDigitalAsset(x)).ToList()
                });
            }
 public async Task <GetDigitalAssetByIdResponse> Handle(GetDigitalAssetByIdRequest request)
 {
     return(new GetDigitalAssetByIdResponse()
     {
         DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context.DigitalAssets.FindAsync(request.Id))
     });
 }
Exemple #3
0
 public async Task <GetDigitalAssetByUniqueIdResponse> Handle(GetDigitalAssetByUniqueIdRequest request)
 {
     return(new GetDigitalAssetByUniqueIdResponse()
     {
         DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context.DigitalAssets.SingleAsync(x => x.UniqueId.ToString() == request.UniqueId))
     });
 }
            public async Task <GetDigitalAssetsResponse> Handle(GetDigitalAssetsRequest request)
            {
                var digitalAssets = await _cache.FromCacheOrServiceAsync <List <DigitalAsset> >(() => _context.DigitalAssets.ToListAsync(), DigitalAssetCacheKeys.DigitalAssets);

                return(new GetDigitalAssetsResponse()
                {
                    DigitalAssets = digitalAssets.Select(x => DigitalAssetApiModel.FromDigitalAsset(x)).ToList()
                });
            }