From 7779116c8adbe927b4d07964f2f103a4b8530fcc Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 15 Feb 2023 18:02:36 +0500 Subject: [PATCH] WellOperationRepository.GetCategories(..) add arg, to filter categories/ --- .../Repositories/IWellOperationRepository.cs | 2 +- .../Repository/WellOperationRepository.cs | 25 +++++++++++-------- .../SAUB/DetectedOperationController.cs | 2 +- .../Controllers/WellOperationController.cs | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index 4075445f..cf9aa40d 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -17,7 +17,7 @@ namespace AsbCloudApp.Repositories /// список названий операций /// /// - IEnumerable GetCategories(); + IEnumerable GetCategories(bool includeParents); /// /// Список секций diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 0c6fcf1d..1c70dd5c 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -34,21 +34,26 @@ namespace AsbCloudInfrastructure.Repository } /// - public IEnumerable GetCategories() + public IEnumerable GetCategories(bool includeParents) { - var allCategories = memoryCache + var categories = memoryCache .GetOrCreateBasic(db); - var parentIds = allCategories - .Select(o => o.IdParent) - .Distinct(); + if (!includeParents) + { + var parentIds = categories + .Select(o => o.IdParent) + .Distinct(); - var operationCategories = allCategories - .Where(o => !parentIds.Contains(o.Id)) + categories = categories + .Where(o => !parentIds.Contains(o.Id)); + } + + var result = categories .OrderBy(o => o.IdParent) - .ThenBy(o => o.Name); + .ThenBy(o => o.Name) + .Adapt>(); - var result = operationCategories.Adapt>(); return result; } @@ -149,7 +154,7 @@ namespace AsbCloudInfrastructure.Repository DurationDepth = o.DepthEnd - o.DepthStart }) .ToListAsync(token); - var parentRelationDictionary = GetCategories() + var parentRelationDictionary = GetCategories(true) .ToDictionary(c => c.Id, c => new { c.Name, diff --git a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs index b4b7c098..244528a3 100644 --- a/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/DetectedOperationController.cs @@ -138,7 +138,7 @@ namespace AsbCloudWebApi.Controllers.SAUB IEnumerable idsWells; if (idCluster is not null) { - var companyWells = await wellService.GetWellsByCompanyAsync((int)idCompany, token); + var companyWells = await wellService.GetAsync(new() { IdCompany = idCompany }, token); idsWells = companyWells.Where(w => w.IdCluster == idCluster) .Select(w=>w.Id); } diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 46ce1683..fd1fdff6 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -56,7 +56,7 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetCategories() { - var result = operationRepository.GetCategories(); + var result = operationRepository.GetCategories(false); return Ok(result); }