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 dbSet; private readonly CacheTable cachedOperationTypes; public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache) { this.context = context; dbSet = context.Set(); cachedOperationTypes = cache.GetCachedTable((DbContext)context); } public async Task> 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 { 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(); //dto.SectionType = item.WellSectionType.Caption; result.Items.Add(dto); } return result; } } }