diff --git a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/DatabaseBlobProvider.cs b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/DatabaseBlobProvider.cs index 3edf68b053..fbccdb067e 100644 --- a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/DatabaseBlobProvider.cs +++ b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/DatabaseBlobProvider.cs @@ -26,8 +26,11 @@ namespace Volo.Abp.BlobStoring.Database { var container = await GetOrCreateContainerAsync(args.ContainerName, args.CancellationToken); - var blob = await DatabaseBlobRepository.FindAsync(container.Id, args.BlobName, - args.CancellationToken); + var blob = await DatabaseBlobRepository.FindAsync( + container.Id, + args.BlobName, + args.CancellationToken + ); var content = await args.BlobStream.GetAllBytesAsync(args.CancellationToken); @@ -40,58 +43,72 @@ namespace Volo.Abp.BlobStoring.Database } blob.SetContent(content); - await DatabaseBlobRepository.UpdateAsync(blob); + + await DatabaseBlobRepository.UpdateAsync(blob, autoSave: true); } else { blob = new DatabaseBlob(GuidGenerator.Create(), container.Id, args.BlobName, content); - await DatabaseBlobRepository.InsertAsync(blob); + await DatabaseBlobRepository.InsertAsync(blob, autoSave: true); } } public override async Task DeleteAsync(BlobProviderDeleteArgs args) { - var container = - await DatabaseBlobContainerRepository.FindAsync(args.ContainerName, - args.CancellationToken); + var container = await DatabaseBlobContainerRepository.FindAsync( + args.ContainerName, + args.CancellationToken + ); if (container == null) { return false; } - return await DatabaseBlobRepository.DeleteAsync(container.Id, args.BlobName, - args.CancellationToken); + return await DatabaseBlobRepository.DeleteAsync( + container.Id, + args.BlobName, + autoSave: true, + cancellationToken: args.CancellationToken + ); } public override async Task ExistsAsync(BlobProviderExistsArgs args) { - var container = - await DatabaseBlobContainerRepository.FindAsync(args.ContainerName, - args.CancellationToken); + var container = await DatabaseBlobContainerRepository.FindAsync( + args.ContainerName, + args.CancellationToken + ); if (container == null) { return false; } - return await DatabaseBlobRepository.ExistsAsync(container.Id, args.BlobName, - args.CancellationToken); + return await DatabaseBlobRepository.ExistsAsync( + container.Id, + args.BlobName, + args.CancellationToken + ); } public override async Task GetOrNullAsync(BlobProviderGetArgs args) { - var container = - await DatabaseBlobContainerRepository.FindAsync(args.ContainerName, - args.CancellationToken); + var container = await DatabaseBlobContainerRepository.FindAsync( + args.ContainerName, + args.CancellationToken + ); if (container == null) { return null; } - var blob = await DatabaseBlobRepository.FindAsync(container.Id, args.BlobName, - args.CancellationToken); + var blob = await DatabaseBlobRepository.FindAsync( + container.Id, + args.BlobName, + args.CancellationToken + ); if (blob == null) { diff --git a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/IDatabaseBlobRepository.cs b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/IDatabaseBlobRepository.cs index 06afcfd28c..e3b96805c2 100644 --- a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/IDatabaseBlobRepository.cs +++ b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/IDatabaseBlobRepository.cs @@ -12,6 +12,6 @@ namespace Volo.Abp.BlobStoring.Database Task ExistsAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default); - Task DeleteAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default); + Task DeleteAsync(Guid containerId, [NotNull] string name, bool autoSave = false, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore/Volo/Abp/BlobStoring/Database/EntityFrameworkCore/EfCoreDatabaseBlobRepository.cs b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore/Volo/Abp/BlobStoring/Database/EntityFrameworkCore/EfCoreDatabaseBlobRepository.cs index f4d1a83466..098f6095e4 100644 --- a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore/Volo/Abp/BlobStoring/Database/EntityFrameworkCore/EfCoreDatabaseBlobRepository.cs +++ b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.EntityFrameworkCore/Volo/Abp/BlobStoring/Database/EntityFrameworkCore/EfCoreDatabaseBlobRepository.cs @@ -7,9 +7,10 @@ using Volo.Abp.EntityFrameworkCore; namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore { - public class EfCoreDatabaseBlobRepository : EfCoreRepository, IDatabaseBlobRepository + public class EfCoreDatabaseBlobRepository : EfCoreRepository, + IDatabaseBlobRepository { - public EfCoreDatabaseBlobRepository(IDbContextProvider dbContextProvider) + public EfCoreDatabaseBlobRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } @@ -38,15 +39,18 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore public virtual async Task DeleteAsync( Guid containerId, string name, + bool autoSave = false, CancellationToken cancellationToken = default) { + //TODO: Should extract this logic to out of the repository and remove this method completely + var blob = await FindAsync(containerId, name, cancellationToken); if (blob == null) { return false; } - await base.DeleteAsync(blob.Id, cancellationToken: GetCancellationToken(cancellationToken)); + await base.DeleteAsync(blob, autoSave, cancellationToken: GetCancellationToken(cancellationToken)); return true; } } diff --git a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs index 60d9e3d148..6c5b034fc1 100644 --- a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs +++ b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.MongoDB/Volo/Abp/BlobStoring/Database/MongoDB/MongoDbDatabaseBlobRepository.cs @@ -29,7 +29,11 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB GetCancellationToken(cancellationToken)); } - public virtual async Task DeleteAsync(Guid containerId, string name, CancellationToken cancellationToken = default) + public virtual async Task DeleteAsync( + Guid containerId, + string name, + bool autoSave = false, + CancellationToken cancellationToken = default) { var blob = await FindAsync(containerId, name, cancellationToken); @@ -38,7 +42,7 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB return false; } - await base.DeleteAsync(blob, cancellationToken: GetCancellationToken(cancellationToken)); + await base.DeleteAsync(blob, autoSave, cancellationToken: GetCancellationToken(cancellationToken)); return true; } }