예제 #1
0
        public async Task DeleteAsync(Entry entry, Image entity)
        {
            dataContext.Images.Remove(entity);
            await dataContext.SaveChangesAsync();

            await fileStorage.DeleteAsync(entry, entity, ImageType.Original);

            await fileStorage.DeleteAsync(entry, entity, ImageType.Preview);

            await fileStorage.DeleteAsync(entry, entity, ImageType.Thumbnail);
        }
예제 #2
0
        public async Task DeleteFileAsync(int fileId)
        {
            var file = await _context.Set <File>()
                       .FindAsync(fileId);

            if (file != null)
            {
                await _fileStorage.DeleteAsync(file.Path);

                var sharedFiles = _context.Set <SharedFile>()
                                  .Where(x => x.FileId == fileId);
                _context.RemoveRange(sharedFiles);
                _context.Remove(file);
                await _context.SaveChangesAsync();
            }
        }
예제 #3
0
        public async Task UpdateAsync(string id, IFormFile imageFile)
        {
            this.ThrowIfIncorrectId(_context.Images, id);

            var image = await _context.Images
                        .FirstOrDefaultAsync(x => x.Id == id);

            _context.Entry(image).State = EntityState.Detached;

            await _blobStorageService.DeleteAsync(image.Caption);

            image.Url = await _blobStorageService.UploadAsync(imageFile.FileName, imageFile.OpenReadStream());

            image.Caption = imageFile.FileName;

            _context.Images.Update(image);
            await _context.SaveChangesAsync();
        }
예제 #4
0
        public void DeleteFile_FileNotExist()
        {
            string       fileName = "file-" + Guid.NewGuid().ToString() + ".dat";
            IFileStorage fs       = PrepaFileStorage("FileStorageConfig");

            var fi = new Fineo.Interfaces.FileInfo();

            fi.Path = fileName;

            var t = fs.DeleteAsync(fi);

            Assert.IsFalse(t.Result);
        }
예제 #5
0
        public static async Task <bool> TryDeleteAsync(this IFileStorage storage, string fileUrl,
                                                       CancellationToken token = default)
        {
            try
            {
                var result = await storage.DeleteAsync(fileUrl, token);

                return(result != null && result.Success);
            }
            catch
            {
                return(false);
            }
        }
예제 #6
0
        public void DeleteFile_WithFolder_Success()
        {
            IFileStorage fs = PrepaFileStorage("FileStorageConfig");

            var fi = new Fineo.Interfaces.FileInfo();

            fi.Path    = "TestSubFolder\\test.csv";
            fi.Content = GetTestFileContent("TestFiles\\test.csv");

            var t = fs.UploadAsync(fi);

            Assert.IsTrue(t.Result, "Failed to upload file - result FALSE");

            t = fs.DeleteAsync(fi);

            Assert.IsTrue(t.Result, "Failed to delete the file");
        }
예제 #7
0
        public async Task DeleteAsync(Guid fileId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var file = await _fileRepository.GetByIdSafely(fileId);

                if (file.UserId != CurrentUserProvider.Id)
                {
                    throw new UnauthorizedAccessException();
                }

                await _fileStorage.DeleteAsync(file.LocationId);

                _fileRepository.Delete(file);
                await uow.CommitAsync();
            }
        }