diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs index 0d9f635f..65666205 100644 --- a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs @@ -5,7 +5,6 @@ using AsbCloudApp.Repositories; using AsbCloudDb; using AsbCloudDb.Model; using AsbCloudInfrastructure.EfCache; -using DocumentFormat.OpenXml.Drawing; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -51,31 +50,31 @@ namespace AsbCloudInfrastructure.Repository public async Task> GetAllAsync(CancellationToken token) { - var dtos = await GetCacheUserRoleAsync(token) + var entities = await GetCacheUserRoleAsync(token) .ConfigureAwait(false); - if (dtos is null) + if (entities is null) return Enumerable.Empty(); - return dtos.Select(Convert); + return entities.Select(Convert); } public UserRoleDto? GetOrDefault(int id) { - var dto = GetCacheUserRole().FirstOrDefault(x => x.Id == id); - if (dto is null) + var entity = GetCacheUserRole().FirstOrDefault(x => x.Id == id); + if (entity is null) return null; - return Convert(dto); + return Convert(entity); } public async Task GetOrDefaultAsync(int id, CancellationToken token) { - var dto = (await GetCacheUserRoleAsync(token) + var entity = (await GetCacheUserRoleAsync(token) .ConfigureAwait(false)).FirstOrDefault(r => r.Id == id); - if (dto is null) + if (entity is null) return null; - return Convert(dto); + return Convert(entity); } public async Task> GetByNamesAsync(IEnumerable names, CancellationToken token) @@ -83,13 +82,13 @@ namespace AsbCloudInfrastructure.Repository if (names?.Any() != true) return Enumerable.Empty(); - var dtos = (await GetCacheUserRoleAsync(token)) + var entities = (await GetCacheUserRoleAsync(token)) .Where(r => names.Contains(r.Caption)); - if (dtos?.Count() != names.Count()) + if (entities?.Count() != names.Count()) throw new ArgumentInvalidException("Invalid role names", nameof(names)); - return dtos.Select(Convert); + return entities.Select(Convert); } public async Task UpdateAsync(UserRoleDto dto, CancellationToken token) @@ -129,12 +128,11 @@ namespace AsbCloudInfrastructure.Repository public async Task DeleteAsync(int id, CancellationToken token) { - var dto = (await GetCacheUserRoleAsync(token)).FirstOrDefault(r => r.Id == id); + var entity = (await GetCacheUserRoleAsync(token)).FirstOrDefault(r => r.Id == id); - if (dto is not null) + if (entity is not null) { - var entity = Convert(dto); - var removeEntity = dbContext.UserRoles.Remove(Convert(entity)); + var removeEntity = dbContext.UserRoles.Remove(entity); await dbContext.SaveChangesAsync(token); DropCacheUserRole(); return removeEntity?.Entity?.Id ?? 0; @@ -170,12 +168,11 @@ namespace AsbCloudInfrastructure.Repository return true; var idPermissionInfo = permissionInfo.Id; - var dtos = GetCacheUserRole() + var entities = GetCacheUserRole() .Where(r => rolesIds.Contains(r.Id)); - var roles = dtos.Select(Convert); - foreach (var role in roles) - if (HasPermission(Convert(role), idPermissionInfo)) + foreach (var role in entities) + if (HasPermission(role, idPermissionInfo)) return true; return false; } @@ -190,10 +187,9 @@ namespace AsbCloudInfrastructure.Repository foreach (var relation in userRole.RelationUserRoleUserRoles) { - var dto = GetCacheUserRole() + var entity = GetCacheUserRole() .First(p => p.Id == relation.IdInclude); - var includedRole = Convert(dto); - if (HasPermission(Convert(includedRole), idPermission, --recursionLevel)) + if (HasPermission(entity, idPermission, --recursionLevel)) return true; } return false; diff --git a/ConsoleApp1/ServiceFactory.cs b/ConsoleApp1/ServiceFactory.cs index df7f8bb4..a1fb9d91 100644 --- a/ConsoleApp1/ServiceFactory.cs +++ b/ConsoleApp1/ServiceFactory.cs @@ -65,7 +65,7 @@ namespace ConsoleApp1 => new TelemetryTracker(CacheDb, ConfigurationService); public static TelemetryService MakeTelemetryService() - => new TelemetryService(Context, MakeTelemetryTracker(), TimezoneService, CacheDb); + => new TelemetryService(Context, MakeTelemetryTracker(), TimezoneService); public static WellService MakeWellService() => new WellService(Context, CacheDb, MakeTelemetryService(), TimezoneService);