diff --git a/AsbCloudApp/Services/IWellOperationService.cs b/AsbCloudApp/Services/IWellOperationService.cs index 40b1c035..475ea9bd 100644 --- a/AsbCloudApp/Services/IWellOperationService.cs +++ b/AsbCloudApp/Services/IWellOperationService.cs @@ -32,5 +32,6 @@ namespace AsbCloudApp.Services CancellationToken token); Task DeleteAsync(IEnumerable ids, CancellationToken token); + IDictionary GetSectionTypes(); } } diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs index 54e43c03..9ac6334e 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs @@ -14,15 +14,20 @@ namespace AsbCloudInfrastructure.Services.WellOperationService { public class WellOperationService : IWellOperationService { - private readonly IAsbCloudDbContext context; + private readonly IAsbCloudDbContext db; private readonly CacheTable cachedOperationCategories; + private readonly CacheTable cachedSectionTypes; - public WellOperationService(IAsbCloudDbContext context, CacheDb cache) + public WellOperationService(IAsbCloudDbContext db, CacheDb cache) { - this.context = context; - cachedOperationCategories = cache.GetCachedTable((DbContext)context); + this.db = db; + cachedOperationCategories = cache.GetCachedTable((DbContext)db); + cachedSectionTypes = cache.GetCachedTable((DbContext)db); } + public IDictionary GetSectionTypes() + => cachedSectionTypes.ToDictionary(s => s.Id, s => s.Caption); + public IEnumerable GetCategories() { var operationTypes = cachedOperationCategories @@ -46,7 +51,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService int take = 32, CancellationToken token = default) { - var query = context.WellOperations + var query = db.WellOperations .Include(s => s.WellSectionType) .Include(s => s.OperationCategory) .Where(s => s.IdWell == idWell); @@ -104,7 +109,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService public async Task GetAsync(int id, CancellationToken token = default) { - var entity = await context.WellOperations + var entity = await db.WellOperations .Include(s => s.WellSectionType) .Include(s => s.OperationCategory) .FirstOrDefaultAsync(e => e.Id == id, token) @@ -128,10 +133,10 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var entity = operationDto.Adapt(); entity.Id = default; entity.IdWell = idWell; - context.WellOperations.Add(entity); + db.WellOperations.Add(entity); } - return await context.SaveChangesAsync(token) + return await db.SaveChangesAsync(token) .ConfigureAwait(false); } @@ -141,17 +146,17 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var entity = item.Adapt(); entity.Id = idOperation; entity.IdWell = idWell; - context.WellOperations.Update(entity); - return await context.SaveChangesAsync(token) + db.WellOperations.Update(entity); + return await db.SaveChangesAsync(token) .ConfigureAwait(false); } public async Task DeleteAsync(IEnumerable ids, CancellationToken token = default) { - var query = context.WellOperations.Where(e => ids.Contains(e.Id)); - context.WellOperations.RemoveRange(query); - return await context.SaveChangesAsync(token) + var query = db.WellOperations.Where(e => ids.Contains(e.Id)); + db.WellOperations.RemoveRange(query); + return await db.SaveChangesAsync(token) .ConfigureAwait(false); } } diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 8bbfd5f5..6fef70ea 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -30,6 +30,20 @@ namespace AsbCloudWebApi.Controllers this.wellOperationImportService = wellOperationImportService; } + /// + /// Возвращает словарь типов секций + /// + /// + [HttpGet] + [Route("sectionTypes")] + [ProducesResponseType(typeof(IDictionary), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetSectionTypes() + { + var result = operationService.GetSectionTypes(); + return Ok(result); + } + + /// /// Возвращает список имен типов операций на скважине ///