forked from ddrilling/AsbCloudServer
WellOperation Controller and Service fix
This commit is contained in:
parent
a8cdda862a
commit
d1f67dc69c
@ -14,24 +14,18 @@ namespace AsbCloudInfrastructure.Services
|
||||
public class WellOperationService : IWellOperationService
|
||||
{
|
||||
private readonly IAsbCloudDbContext context;
|
||||
private readonly CacheTable<WellOperationCategory> cachedOperationTypes;
|
||||
private readonly CacheTable<WellOperationCategory> cachedOperationCategories;
|
||||
|
||||
public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache)
|
||||
{
|
||||
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 result = new List<WellOperationCategoryDto>();
|
||||
|
||||
foreach(var op in operationTypes)
|
||||
{
|
||||
var dto = op.Adapt<WellOperationCategoryDto>();
|
||||
result.Add(dto);
|
||||
}
|
||||
var operationTypes = cachedOperationCategories.Where().Distinct();
|
||||
var result = operationTypes.Adapt<WellOperationCategoryDto>();
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -42,8 +36,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var query = context.WellOperations
|
||||
.Include(s => s.WellSectionType)
|
||||
.Include(s => s.OperationCategory)
|
||||
.Where(s => s.IdWell == idWell)
|
||||
.AsNoTracking();
|
||||
.Where(s => s.IdWell == idWell);
|
||||
|
||||
var result = new PaginationContainer<WellOperationDto>
|
||||
{
|
||||
@ -58,9 +51,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (skip > 0)
|
||||
query = query.Skip(skip);
|
||||
|
||||
query = query.Take(take);
|
||||
|
||||
var entities = await query.Take(take)
|
||||
var entities = await query.Take(take).AsNoTracking()
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
|
||||
foreach (var item in entities)
|
||||
@ -127,8 +118,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
public async Task<int> DeleteAsync(IEnumerable<int> ids,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var entities = context.WellOperations.Where(e => ids.Contains(e.Id));
|
||||
context.WellOperations.RemoveRange(entities);
|
||||
var query = context.WellOperations.Where(e => ids.Contains(e.Id));
|
||||
context.WellOperations.RemoveRange(query);
|
||||
return await context.SaveChangesAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[Route("types")]
|
||||
[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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user