diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 2ca837d3..52c087fa 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -90,10 +90,10 @@ namespace AsbCloudInfrastructure.Repository public async Task UpdateAsync(UserRoleDto dto, CancellationToken token) { - var entity = Convert(dto); await UpdatePermissionsAsync(dto, token); await UpdateIncludedRolesAsync(dto, token); + var entity = Convert(dto); var result = dbContext.UserRoles.Upsert(entity); await dbContext.SaveChangesAsync(token); DropCacheUserRole(); @@ -182,8 +182,15 @@ namespace AsbCloudInfrastructure.Repository if (dto?.Roles is null) return; - var relations = (await GetCacheRelationUserRoleUserRoleAsync(token).ConfigureAwait(false)) - .Where(r => r.Id == dto.Id); + var idsIncludeRole = dto.Roles.Select(x => x.Id); + + if (idsIncludeRole.Any(x => x == dto.Id)) + throw new ArgumentInvalidException("Invalid include role", nameof(UserRoleDto)); + + var relations = await dbContext.RelationUserRoleUserRoles + .Where(r => r.Id == dto.Id) + .ToListAsync(token) + .ConfigureAwait(false); dbContext.RelationUserRoleUserRoles.RemoveRange(relations); @@ -201,9 +208,10 @@ namespace AsbCloudInfrastructure.Repository if (dto?.Permissions is null) return; - var relations = (await GetCacheRelationUserRolePermissionsAsync(token).ConfigureAwait(false)) - .Where(r => r.IdUserRole == dto.Id); - + var relations = await dbContext.RelationUserRolePermissions + .Where(r => r.IdUserRole == dto.Id) + .ToListAsync(token) + .ConfigureAwait(false); dbContext.RelationUserRolePermissions.RemoveRange(relations); if (dto.Permissions.Any())