WellOperation Controller and Service fix

This commit is contained in:
KharchenkoVV 2021-08-17 09:20:31 +05:00
parent a8cdda862a
commit d1f67dc69c
2 changed files with 11 additions and 20 deletions

View File

@ -14,24 +14,18 @@ namespace AsbCloudInfrastructure.Services
public class WellOperationService : IWellOperationService public class WellOperationService : IWellOperationService
{ {
private readonly IAsbCloudDbContext context; private readonly IAsbCloudDbContext context;
private readonly CacheTable<WellOperationCategory> cachedOperationTypes; private readonly CacheTable<WellOperationCategory> cachedOperationCategories;
public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache) public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache)
{ {
this.context = context; this.context = context;
cachedOperationTypes = cache.GetCachedTable<WellOperationCategory>((DbContext)context); cachedOperationCategories = cache.GetCachedTable<WellOperationCategory>((DbContext)context);
} }
public IEnumerable<WellOperationCategoryDto> GetTypes() public IEnumerable<WellOperationCategoryDto> GetCategories()
{ {
var operationTypes = cachedOperationTypes.Where().Distinct(); var operationTypes = cachedOperationCategories.Where().Distinct();
var result = new List<WellOperationCategoryDto>(); var result = operationTypes.Adapt<WellOperationCategoryDto>();
foreach(var op in operationTypes)
{
var dto = op.Adapt<WellOperationCategoryDto>();
result.Add(dto);
}
return result; return result;
} }
@ -42,8 +36,7 @@ namespace AsbCloudInfrastructure.Services
var query = context.WellOperations var query = context.WellOperations
.Include(s => s.WellSectionType) .Include(s => s.WellSectionType)
.Include(s => s.OperationCategory) .Include(s => s.OperationCategory)
.Where(s => s.IdWell == idWell) .Where(s => s.IdWell == idWell);
.AsNoTracking();
var result = new PaginationContainer<WellOperationDto> var result = new PaginationContainer<WellOperationDto>
{ {
@ -58,9 +51,7 @@ namespace AsbCloudInfrastructure.Services
if (skip > 0) if (skip > 0)
query = query.Skip(skip); query = query.Skip(skip);
query = query.Take(take); var entities = await query.Take(take).AsNoTracking()
var entities = await query.Take(take)
.ToListAsync(token).ConfigureAwait(false); .ToListAsync(token).ConfigureAwait(false);
foreach (var item in entities) foreach (var item in entities)
@ -127,8 +118,8 @@ namespace AsbCloudInfrastructure.Services
public async Task<int> DeleteAsync(IEnumerable<int> ids, public async Task<int> DeleteAsync(IEnumerable<int> ids,
CancellationToken token = default) CancellationToken token = default)
{ {
var entities = context.WellOperations.Where(e => ids.Contains(e.Id)); var query = context.WellOperations.Where(e => ids.Contains(e.Id));
context.WellOperations.RemoveRange(entities); context.WellOperations.RemoveRange(query);
return await context.SaveChangesAsync(token) return await context.SaveChangesAsync(token)
.ConfigureAwait(false); .ConfigureAwait(false);
} }

View File

@ -32,9 +32,9 @@ namespace AsbCloudWebApi.Controllers
[HttpGet] [HttpGet]
[Route("types")] [Route("types")]
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetTypesAsync() public IActionResult GetTypes()
{ {
var result = operationService.GetTypes(); var result = operationService.GetCategories();
return Ok(result); return Ok(result);
} }