DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/DrillFlowChartService.cs
2021-10-13 17:34:32 +05:00

76 lines
2.5 KiB
C#

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<DrillFlowChartParamsDto, DrillFlowChartParams>,
IDrillFlowChartService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
public DrillFlowChartService(IAsbCloudDbContext context, ITelemetryService telemetryService)
: base(context)
{
this.db = context;
this.telemetryService = telemetryService;
}
public async Task<IEnumerable<DrillFlowChartParamsDto>> GetAllAsync(int idWell,
CancellationToken token = default)
{
var entities = await (from p in db.DrillFlowChartParams
where p.IdWell == idWell
orderby p.Id
select p)
.ToListAsync(token)
.ConfigureAwait(false);
var dto = entities.Adapt<DrillFlowChartParamsDto>();
return dto;
}
public async Task<int> InsertAsync(int idWell, DrillFlowChartParamsDto 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<int> InsertRangeAsync(int idWell, IEnumerable<DrillFlowChartParamsDto> 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<int> UpdateAsync(int idWell, int idDto, DrillFlowChartParamsDto dto,
CancellationToken token = default)
{
dto.IdWell = idWell;
dto.LastUpdate = DateTime.Now;
var result = await base.UpdateAsync(idDto, dto, token).ConfigureAwait(false);
return result;
}
}
}