This commit is contained in:
ai.astrakhantsev 2022-11-08 11:55:47 +05:00
parent 6ac073d59a
commit 408429a0b5
2 changed files with 21 additions and 25 deletions

View File

@ -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<IEnumerable<UserRoleDto>> 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<UserRoleDto>();
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<UserRoleDto?> 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<IEnumerable<UserRoleDto>> GetByNamesAsync(IEnumerable<string> names, CancellationToken token)
@ -83,13 +82,13 @@ namespace AsbCloudInfrastructure.Repository
if (names?.Any() != true)
return Enumerable.Empty<UserRoleDto>();
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<int> UpdateAsync(UserRoleDto dto, CancellationToken token)
@ -129,12 +128,11 @@ namespace AsbCloudInfrastructure.Repository
public async Task<int> 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;

View File

@ -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);