using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Repository; using Mapster; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { public class DrillFlowChartService : CrudWellRelatedServiceBase, IDrillFlowChartService { private readonly IAsbCloudDbContext db; private readonly IWellService wellService; public DrillFlowChartService(IAsbCloudDbContext context, IWellService wellService) : base(context) { this.db = context; this.wellService = wellService; } public async Task> GetAllAsync(int idWell, DateTime updateFrom, CancellationToken token = default) { var timezone = wellService.GetTimezone(idWell); var updateFromUtc = updateFrom.ToUtcDateTimeOffset(timezone.Hours); var entities = await GetQuery() .Where(e => e.IdWell == idWell) .Where(e => e.LastUpdate == updateFromUtc) .OrderBy(e => e.DepthStart) .ThenBy(e => e.Id) .ToListAsync(token) .ConfigureAwait(false); var dtos = entities.Select(entity => { var dto = entity.Adapt(); dto.LastUpdate = entity.LastUpdate.ToRemoteDateTime(timezone.Hours); return dto; }); return dtos; } public override async Task InsertAsync(DrillFlowChartDto dto, CancellationToken token = default) { dto.LastUpdate = DateTime.UtcNow; var result = await base.InsertAsync(dto, token); return result; } public override async Task UpdateAsync(DrillFlowChartDto dto, CancellationToken token = default) { dto.LastUpdate = DateTime.UtcNow; var result = await base.UpdateAsync(dto, token); return result; } } }