DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellOperationService.cs

62 lines
1.9 KiB
C#

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
namespace AsbCloudInfrastructure.Services
{
public class WellOperationService : IWellOperationService
{
private readonly IAsbCloudDbContext context;
private readonly DbSet<WellOperation> dbSet;
private readonly CacheTable<OperationCategory> cachedOperationTypes;
public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache)
{
this.context = context;
dbSet = context.Set<WellOperation>();
cachedOperationTypes = cache.GetCachedTable<OperationCategory>((DbContext)context);
}
public async Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
int skip = 0, int take = 32, CancellationToken token = default)
{
var query = dbSet
.Include(s => s.WellSectionType)
.Where(s => s.IdWell == idWell)
.AsNoTracking();
var result = new PaginationContainer<WellOperationDto>
{
Skip = skip,
Take = take,
Count = await query.CountAsync(token).ConfigureAwait(false),
};
query = query
.OrderBy(e => e.WellDepth);
if (skip > 0)
query = query.Skip(skip);
query = query.Take(take);
var entities = await query.Take(take).ToListAsync(token).ConfigureAwait(false);
foreach (var item in entities)
{
var dto = item.Adapt<WellOperationDto>();
//dto.SectionType = item.WellSectionType.Caption;
result.Items.Add(dto);
}
return result;
}
}
}