diff --git a/AsbCloudApp/Data/LimitingParameterDto.cs b/AsbCloudApp/Data/LimitingParameterDto.cs
index 2c03eb45..a1f03219 100644
--- a/AsbCloudApp/Data/LimitingParameterDto.cs
+++ b/AsbCloudApp/Data/LimitingParameterDto.cs
@@ -27,6 +27,16 @@ namespace AsbCloudApp.Data
/// Идентификатор критерия бурения
///
public short IdFeedRegulator { get; set; }
+
+ ///
+ /// Наименование критерия бурения
+ ///
+ public string NameFeedRegulator { get; set; } = string.Empty;
+
+ ///
+ /// Количество включений
+ ///
+ public int NumberInclusions { get; set; }
}
#nullable disable
}
diff --git a/AsbCloudInfrastructure/Repository/UserRoleRepository.cs b/AsbCloudInfrastructure/Repository/UserRoleRepository.cs
index 2ca837d3..ea11b60c 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();
@@ -177,13 +177,29 @@ namespace AsbCloudInfrastructure.Repository
return false;
}
+ private IEnumerable GetNestedByIds(IEnumerable ids, int recursionLevel = 7)
+ {
+ var roles = new List();
+ foreach (var id in ids)
+ roles.AddRange(GetNestedById(id, recursionLevel));
+
+ return roles;
+ }
+
private async Task UpdateIncludedRolesAsync(UserRoleDto dto, CancellationToken token)
{
if (dto?.Roles is null)
return;
- var relations = (await GetCacheRelationUserRoleUserRoleAsync(token).ConfigureAwait(false))
- .Where(r => r.Id == dto.Id);
+ var idsIncludeRole = GetNestedByIds(dto.Roles.Select(x => x.Id)).Select(x => x.Id);
+
+ if (idsIncludeRole is not null && idsIncludeRole.Any(x => x == dto.Id))
+ throw new ArgumentInvalidException("Invalid include role (self reference)", nameof(dto));
+
+ var relations = await dbContext.RelationUserRoleUserRoles
+ .Where(r => r.Id == dto.Id)
+ .ToListAsync(token)
+ .ConfigureAwait(false);
dbContext.RelationUserRoleUserRoles.RemoveRange(relations);
@@ -201,9 +217,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())
@@ -235,19 +252,9 @@ namespace AsbCloudInfrastructure.Repository
private void DropCacheUserRole()
=> dbContext.RelationUserUserRoles.DropCache(userRoleCacheTag);
- private Task> GetCacheRelationUserRoleUserRoleAsync(CancellationToken token)
- => dbContext.RelationUserRoleUserRoles
- .Include(r => r.IncludeRole)
- .Include(r => r.Role)
- .FromCacheAsync(relationUserRoleUserRoleCacheTag, relationCacheObsolence, token);
private void DropCacheRelationUserRoleUserRole()
=> dbContext.RelationUserUserRoles.DropCache(relationUserRoleUserRoleCacheTag);
- private Task> GetCacheRelationUserRolePermissionsAsync(CancellationToken token)
- => dbContext.RelationUserRolePermissions
- .Include(r => r.UserRole)
- .Include(r => r.Permission)
- .FromCacheAsync(relationUserRolePermissionsCacheTag, relationCacheObsolence, token);
private IEnumerable GetCacheRelationUserRolePermissions()
=> dbContext.RelationUserRolePermissions
.Include(r => r.UserRole)
diff --git a/AsbCloudInfrastructure/Services/LimitingParameterService.cs b/AsbCloudInfrastructure/Services/LimitingParameterService.cs
index 34ebbd24..c50729f8 100644
--- a/AsbCloudInfrastructure/Services/LimitingParameterService.cs
+++ b/AsbCloudInfrastructure/Services/LimitingParameterService.cs
@@ -15,6 +15,14 @@ namespace AsbCloudInfrastructure.Services
{
private readonly ILimitingParameterRepository limitingParameterRepository;
private readonly IWellService wellService;
+ private readonly Dictionary feedRegulatorData = new Dictionary()
+ {
+ { 0, "Нет ограничения" },
+ { 1, "МСП" },
+ { 2, "Давление" },
+ { 3, "Осевая нагрузка" },
+ { 4, "Момент" }
+ };
public LimitingParameterService(ILimitingParameterRepository limitingParameterRepository,
IWellService wellService)
@@ -46,7 +54,9 @@ namespace AsbCloudInfrastructure.Services
IdWell = well.Id,
IdFeedRegulator = item.Key,
Depth = allItemDepths,
- TotalMinutes = (float)allItemDates
+ TotalMinutes = (float)allItemDates,
+ NumberInclusions = item.Count(),
+ NameFeedRegulator = feedRegulatorData.GetValueOrDefault(item.Key) ?? $"Id: {item.Key}"
});
}