using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudDb.Model.ProcessMaps; using Microsoft.EntityFrameworkCore; namespace AsbCloudInfrastructure.Repository; internal class WellReamProcessMapRepository : CrudWellRelatedRepositoryBase, IWellReamProcessMapRepository { private readonly IWellService wellService; public WellReamProcessMapRepository(IAsbCloudDbContext context, IWellService wellService) : base(context, dbSet => dbSet.Include(p => p.Well)) { this.wellService = wellService; } public async Task> GetAsync(WellReamProcessMapRequest request, CancellationToken cancellationToken) { var query = GetQuery() .Where(p => p.IdWell == request.IdWell); if (request.UpdateFrom is not null) { var timezone = wellService.GetTimezone(request.IdWell); var updateFromUtc = request.UpdateFrom?.ToUtcDateTimeOffset(timezone.Hours); query = query.Where(p => p.LastUpdate >= updateFromUtc); } var entities = await query.OrderBy(e => e.DepthStart) .ThenBy(e => e.Id) .AsNoTracking() .ToArrayAsync(cancellationToken); return entities.Select(Convert); } }