using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.EntityFrameworkCore; using Mapster; namespace AsbCloudInfrastructure.Services { public class DrillFlowChartService : CrudServiceBase, IDrillFlowChartService { private readonly IAsbCloudDbContext db; public DrillFlowChartService(IAsbCloudDbContext context) : base(context) { this.db = context; } public async Task> GetAllAsync(int idWell, DateTime updateFrom, CancellationToken token = default) { var entities = await (from p in db.DrillFlowChart where p.IdWell == idWell && p.LastUpdate > updateFrom orderby p.DepthStart, p.Id select p) .ToListAsync(token) .ConfigureAwait(false); var dto = entities.Adapt(); return dto; } public async Task InsertAsync(int idWell, DrillFlowChartDto dto, CancellationToken token = default) { dto.IdWell = idWell; dto.LastUpdate = DateTime.Now; var result = await base.InsertAsync(dto, token).ConfigureAwait(false); return result; } public async Task InsertRangeAsync(int idWell, IEnumerable dtos, CancellationToken token = default) { foreach (var dto in dtos) { dto.IdWell = idWell; dto.LastUpdate = DateTime.Now; } var result = await base.InsertRangeAsync(dtos, token).ConfigureAwait(false); return result; } public async Task UpdateAsync(int idWell, int idDto, DrillFlowChartDto dto, CancellationToken token = default) { dto.IdWell = idWell; dto.LastUpdate = DateTime.Now; var result = await base.UpdateAsync(idDto, dto, token).ConfigureAwait(false); return result; } } }