예제 #1
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);

                digitalAsset.IsDeleted = true;

                await _context.SaveChangesAsync(request.Username);

                _cache.Remove(DigitalAssetsCacheKeyFactory.Get(request.TenantUniqueId));
                _cache.Remove(DigitalAssetsCacheKeyFactory.GetByUniqueId(request.TenantUniqueId, $"{digitalAsset.UniqueId}"));

                return(new Response());
            }
예제 #2
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))
                });
            }
예제 #4
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()
                });
            }