forked from ddrilling/AsbCloudServer
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Exceptions;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
|
{
|
|
internal class ActualTrajectoryRepository : IActualTrajectoryRepository
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
private readonly IWellService wellService;
|
|
public ActualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService)
|
|
{
|
|
this.db = db;
|
|
this.wellService = wellService;
|
|
}
|
|
|
|
public async Task<TrajectoryDto[]> GetTrajectoryAsync(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 entities = await db.Record7
|
|
.AsNoTracking()
|
|
.Where(x => x.IdTelemetry == well.IdTelemetry)
|
|
.Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null)
|
|
.OrderBy(e => e.Deptsvym)
|
|
.Select(x => new { x.Deptsvym, x.Svyinc, x.Svyazc })
|
|
.ToArrayAsync(token);
|
|
|
|
var result = entities
|
|
.Select(coord => new TrajectoryDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value))
|
|
.ToArray();
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|