예제 #1
0
 public async Task <GetDigitalAssetByIdResponse> Handle(GetDigitalAssetByIdRequest request)
 {
     return(new GetDigitalAssetByIdResponse()
     {
         DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context.DigitalAssets.FindAsync(request.Id))
     });
 }
예제 #2
0
 public async Task <GetDigitalAssetByUniqueIdResponse> Handle(GetDigitalAssetByUniqueIdRequest request)
 {
     return(new GetDigitalAssetByUniqueIdResponse()
     {
         DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context.DigitalAssets.SingleAsync(x => x.UniqueId.ToString() == request.UniqueId))
     });
 }
예제 #3
0
            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()
                });
            }
예제 #4
0
            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()
                });
            }
예제 #5
0
            public async Task <Response> Handle(Request request)
            {
                var digitalAsset = await _context.DigitalAssets
                                   .Include(x => x.Tenant)
                                   .SingleAsync(x => x.Id == request.Id && x.Tenant.UniqueId == request.TenantUniqueId);

                return(new Response()
                {
                    DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(digitalAsset)
                });
            }
예제 #6
0
            public async Task <Response> Handle(Request request)
            {
                var digitalAssets = await _cache.FromCacheOrServiceAsync <List <DigitalAsset> >(() => _context
                                                                                                .DigitalAssets
                                                                                                .Include(x => x.Tenant)
                                                                                                .Where(x => x.Tenant.UniqueId == request.TenantUniqueId)
                                                                                                .ToListAsync(), DigitalAssetsCacheKeyFactory.Get(request.TenantUniqueId));

                return(new Response()
                {
                    DigitalAssets = digitalAssets.Select(x => DigitalAssetApiModel.FromDigitalAsset(x)).ToList()
                });
            }
            public async Task <Response> Handle(Request request)
            {
                var digitalAssets = await _context
                                    .DigitalAssets
                                    .Include(x => x.Tenant)
                                    .Where(x => x.Tenant.UniqueId == request.TenantUniqueId)
                                    .Take(5)
                                    .ToListAsync();

                return(new Response()
                {
                    DigitalAssets = digitalAssets.Select(x => DigitalAssetApiModel.FromDigitalAsset(x)).ToList()
                });
            }
예제 #8
0
            public async Task <UploadDigitalAssetResponse> Handle(Request request)
            {
                var tenant = _context.Tenants.Where(x => x.UniqueId == request.TenantUniqueId).Single();
                var user   = _context.Users
                             .Include(x => x.Tenant)
                             .Where(x => x.Username == request.Username)
                             .Single();

                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.IsSecure    = request.IsSecure;
                    digitalAsset.Tenant      = tenant;
                    digitalAsset.ContentType = $"{file.Headers.ContentType}";
                    digitalAsset.UploadedOn  = DateTime.UtcNow;
                    digitalAsset.UploadedBy  = user.Name;
                    digitalAsset.Size        = $"{Math.Round(ByteSize.FromBytes(Convert.ToDouble(digitalAsset.Bytes.Length)).KiloBytes, 1)} KB";
                    _context.DigitalAssets.Add(digitalAsset);
                    digitalAssets.Add(digitalAsset);
                }

                await _context.SaveChangesAsync(request.Username);

                _cache.Remove(DigitalAssetsCacheKeyFactory.Get(request.TenantUniqueId));

                return(new UploadDigitalAssetResponse()
                {
                    DigitalAssets = digitalAssets.Select(x => DigitalAssetApiModel.FromDigitalAsset(x)).ToList()
                });
            }
            public async Task <Response> Handle(Request request)
            {
                if (string.IsNullOrEmpty(request.OAuthToken))
                {
                    return new Response()
                           {
                               DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _cache.FromCacheOrServiceAsync <DigitalAsset>(() => _context
                                                                                                                                        .DigitalAssets
                                                                                                                                        .Include(x => x.Tenant)
                                                                                                                                        .SingleAsync(x => x.UniqueId.ToString() == request.UniqueId && x.IsSecure == false), DigitalAssetsCacheKeyFactory.GetByUniqueId(request.TenantUniqueId, request.UniqueId)))
                           }
                }
                ;

                return(new Response()
                {
                    DigitalAsset = DigitalAssetApiModel.FromDigitalAsset(await _context
                                                                         .DigitalAssets
                                                                         .Include(x => x.Tenant)
                                                                         .SingleAsync(x => x.UniqueId.ToString() == request.UniqueId && x.Tenant.UniqueId == request.TenantUniqueId))
                });
            }