2021-10-13 17:34:32 +05:00
|
|
|
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
|
|
|
|
{
|
2021-10-14 10:18:43 +05:00
|
|
|
public class DrillFlowChartService : CrudServiceBase<DrillFlowChartDto, DrillFlowChart>,
|
2021-10-13 17:34:32 +05:00
|
|
|
IDrillFlowChartService
|
|
|
|
{
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2021-10-18 12:38:49 +05:00
|
|
|
|
|
|
|
public DrillFlowChartService(IAsbCloudDbContext context)
|
2021-10-13 17:34:32 +05:00
|
|
|
: base(context)
|
|
|
|
{
|
|
|
|
this.db = context;
|
|
|
|
}
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
public async Task<IEnumerable<DrillFlowChartDto>> GetAllAsync(int idWell,
|
|
|
|
DateTime updateFrom, CancellationToken token = default)
|
2021-10-13 17:34:32 +05:00
|
|
|
{
|
2021-10-14 10:18:43 +05:00
|
|
|
var entities = await (from p in db.DrillFlowChart
|
|
|
|
where p.IdWell == idWell &&
|
2021-11-02 17:50:43 +05:00
|
|
|
p.LastUpdate > updateFrom
|
2021-10-31 16:35:09 +05:00
|
|
|
orderby p.DepthStart, p.Id
|
2021-10-13 17:34:32 +05:00
|
|
|
select p)
|
|
|
|
.ToListAsync(token)
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
var dto = entities.Adapt<DrillFlowChartDto>();
|
2021-10-13 17:34:32 +05:00
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
public async Task<int> InsertAsync(int idWell, DrillFlowChartDto dto,
|
2021-10-13 17:34:32 +05:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
dto.LastUpdate = DateTime.Now;
|
|
|
|
|
|
|
|
var result = await base.InsertAsync(dto, token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
public async Task<int> InsertRangeAsync(int idWell, IEnumerable<DrillFlowChartDto> dtos,
|
2021-10-13 17:34:32 +05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
public async Task<int> UpdateAsync(int idWell, int idDto, DrillFlowChartDto dto,
|
2021-10-13 17:34:32 +05:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
dto.LastUpdate = DateTime.Now;
|
|
|
|
|
|
|
|
var result = await base.UpdateAsync(idDto, dto, token).ConfigureAwait(false);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|