forked from ddrilling/AsbCloudServer
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Data.ProcessMaps;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudApp.Requests;
|
|
using AsbCloudDb.Model;
|
|
using Mapster;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
public class WellCompositeRepository : IWellCompositeRepository
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
private readonly IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository;
|
|
|
|
public WellCompositeRepository(
|
|
IAsbCloudDbContext db,
|
|
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository)
|
|
{
|
|
this.db = db;
|
|
this.processMapPlanDrillingRepository = processMapPlanDrillingRepository;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<IEnumerable<WellCompositeDto>> GetAsync(int idWell, CancellationToken token)
|
|
{
|
|
var entities = await db.WellComposites
|
|
.Where(c => c.IdWell == idWell)
|
|
.AsNoTracking()
|
|
.ToListAsync(token)
|
|
.ConfigureAwait(false);
|
|
return entities.Select(Convert);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token)
|
|
{
|
|
db.WellComposites.RemoveRange(db.WellComposites
|
|
.Where(c => c.IdWell == idWell));
|
|
|
|
var entities = wellComposites
|
|
.Select(w => Convert(idWell, w));
|
|
|
|
db.WellComposites.AddRange(entities);
|
|
return db.SaveChangesAsync(token);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public Task<IEnumerable<ProcessMapPlanDrillingDto>> GetCompositeProcessMap(int idWell, CancellationToken token)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static WellComposite Convert(int idWell, WellCompositeDto dto)
|
|
{
|
|
var entity = dto.Adapt<WellComposite>();
|
|
entity.IdWell = idWell;
|
|
return entity;
|
|
}
|
|
private static WellCompositeDto Convert(WellComposite entity)
|
|
{
|
|
var dto = entity.Adapt<WellCompositeDto>();
|
|
return dto;
|
|
}
|
|
}
|
|
|