diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index a56b78ca2a..939d9739d2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -41,54 +41,44 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Create)] public async Task CreateAsync(IdentityRoleCreateDto input) { - using (_roleManager.AutoSaveRoleChanges(false)) - { - var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); + var role = new IdentityRole(GuidGenerator.Create(), input.Name, CurrentTenant.Id); - role.IsDefault = input.IsDefault; - role.IsPublic = input.IsPublic; + role.IsDefault = input.IsDefault; + role.IsPublic = input.IsPublic; - (await _roleManager.CreateAsync(role)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + (await _roleManager.CreateAsync(role)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(role); - } + return ObjectMapper.Map(role); } [Authorize(IdentityPermissions.Roles.Update)] public async Task UpdateAsync(Guid id, IdentityRoleUpdateDto input) { - using (_roleManager.AutoSaveRoleChanges(false)) - { - var role = await _roleManager.GetByIdAsync(id); - role.ConcurrencyStamp = input.ConcurrencyStamp; + var role = await _roleManager.GetByIdAsync(id); + role.ConcurrencyStamp = input.ConcurrencyStamp; - (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); + (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); - role.IsDefault = input.IsDefault; - role.IsPublic = input.IsPublic; + role.IsDefault = input.IsDefault; + role.IsPublic = input.IsPublic; - (await _roleManager.UpdateAsync(role)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + (await _roleManager.UpdateAsync(role)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(role); - } + return ObjectMapper.Map(role); } [Authorize(IdentityPermissions.Roles.Delete)] public async Task DeleteAsync(Guid id) { - using (_roleManager.AutoSaveRoleChanges(false)) + var role = await _roleManager.FindByIdAsync(id.ToString()); + if (role == null) { - var role = await _roleManager.FindByIdAsync(id.ToString()); - if (role == null) - { - return; - } - - (await _roleManager.DeleteAsync(role)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + return; } + + (await _roleManager.DeleteAsync(role)).CheckErrors(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index df22e1b985..ad87b0041f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -53,55 +53,45 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Users.Create)] public async Task CreateAsync(IdentityUserCreateDto input) { - using (_userManager.AutoSaveUserChanges(false)) - { - var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); + var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); - (await _userManager.CreateAsync(user, input.Password)).CheckErrors(); - await UpdateUserByInput(user, input); + (await _userManager.CreateAsync(user, input.Password)).CheckErrors(); + await UpdateUserByInput(user, input); - await CurrentUnitOfWork.SaveChangesAsync(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(user); - } + return ObjectMapper.Map(user); } [Authorize(IdentityPermissions.Users.Update)] public async Task UpdateAsync(Guid id, IdentityUserUpdateDto input) { - using (_userManager.AutoSaveUserChanges(false)) - { - var user = await _userManager.GetByIdAsync(id); - user.ConcurrencyStamp = input.ConcurrencyStamp; + var user = await _userManager.GetByIdAsync(id); + user.ConcurrencyStamp = input.ConcurrencyStamp; - (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); - await UpdateUserByInput(user, input); - (await _userManager.UpdateAsync(user)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); + await UpdateUserByInput(user, input); + (await _userManager.UpdateAsync(user)).CheckErrors(); + await CurrentUnitOfWork.SaveChangesAsync(); - return ObjectMapper.Map(user); - } + return ObjectMapper.Map(user); } [Authorize(IdentityPermissions.Users.Delete)] public async Task DeleteAsync(Guid id) { - using (_userManager.AutoSaveUserChanges(false)) + if (CurrentUser.Id == id) { - if (CurrentUser.Id == id) - { - throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); - } - - var user = await _userManager.FindByIdAsync(id.ToString()); - if (user == null) - { - return; - } - - (await _userManager.DeleteAsync(user)).CheckErrors(); - await CurrentUnitOfWork.SaveChangesAsync(); + throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); } + + var user = await _userManager.FindByIdAsync(id.ToString()); + if (user == null) + { + return; + } + + (await _userManager.DeleteAsync(user)).CheckErrors(); } [Authorize(IdentityPermissions.Users.Update)] diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs deleted file mode 100644 index af4cb3362f..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityStoreAutoSaveChanges.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.Identity -{ - public interface IIdentityStoreAutoSaveChanges - { - bool AutoSaveChanges { get; set; } - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs index 429012bfca..c66d501146 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs @@ -69,20 +69,5 @@ namespace Volo.Abp.Identity return await base.DeleteAsync(role); } - - public IDisposable AutoSaveRoleChanges(bool autoSaveChanges) - { - if (!(Store is IIdentityStoreAutoSaveChanges store)) - { - throw new InvalidOperationException(Store.GetType().FullName + " does not support AutoSaveChanges"); - } - - var currentAutoSaveChanges = store.AutoSaveChanges; - store.AutoSaveChanges = autoSaveChanges; - return new DisposeAction(() => - { - store.AutoSaveChanges = currentAutoSaveChanges; - }); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs index 60c41ab0a8..175b051a48 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs @@ -20,7 +20,6 @@ namespace Volo.Abp.Identity public class IdentityRoleStore : IRoleStore, IRoleClaimStore, - IIdentityStoreAutoSaveChanges, ITransientDependency { private readonly IIdentityRoleRepository _roleRepository; diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index 7212b8f0d2..dc4b2fe4b2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -75,20 +75,5 @@ namespace Volo.Abp.Identity return IdentityResult.Success; } - - public IDisposable AutoSaveUserChanges(bool autoSaveChanges) - { - if (!(Store is IIdentityStoreAutoSaveChanges store)) - { - throw new InvalidOperationException(Store.GetType().FullName + " does not support AutoSaveChanges"); - } - - var currentAutoSaveChanges = store.AutoSaveChanges; - store.AutoSaveChanges = autoSaveChanges; - return new DisposeAction(() => - { - store.AutoSaveChanges = currentAutoSaveChanges; - }); - } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index 9e302ef6c9..bac63a0c11 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -31,7 +31,6 @@ namespace Volo.Abp.Identity IUserAuthenticationTokenStore, IUserAuthenticatorKeyStore, IUserTwoFactorRecoveryCodeStore, - IIdentityStoreAutoSaveChanges, ITransientDependency { private const string InternalLoginProvider = "[AspNetUserStore]";