using AsbCloudApp.Data.WITS; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { internal class FactualTrajectoryRepository : IFactualTrajectoryRepository { private readonly IAsbCloudDbContext db; private readonly IWellService wellService; public FactualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) { this.db = db; this.wellService = wellService; } public async Task> GetAsync(int idWell, CancellationToken token) { var well = wellService.GetOrDefault(idWell); if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); var query = db.Record7 .AsNoTracking() .Where(x => x.IdTelemetry == well.IdTelemetry); var entities = await query .OrderBy(e => e.Deptsvym) .ToListAsync(token); var result = entities .Select(r => new Record7Dto() { IdTelemetry = r.IdTelemetry, Deptsvym = r.Deptsvym, Svyinc = r.Svyinc, Svyazc = r.Svyazc }); return result; } } }