Пример #1
0
 public async Task <Response> Handle(Request request)
 {
     return(new Response()
     {
         DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context.DigitalAssets.FindAsync(request.Id))
     });
 }
            public async Task <UploadDigitalAssetResponse> Handle(Request 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 <Response> Handle(Request request)
 {
     return(new Response()
     {
         DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context.DigitalAssets.SingleAsync(x => x.UniqueId.ToString() == request.UniqueId))
     });
 }
Пример #4
0
            public async Task <Response> Handle(Request request)
            {
                var digitalAssets = await _cache.FromCacheOrServiceAsync <List <DigitalAsset> >(() => _context.DigitalAssets.ToListAsync(), DigitalAssetCacheKeys.DigitalAssets);

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