DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/WellCompositeRepository.cs

73 lines
2.2 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
2023-01-26 15:37:46 +05:00
using AsbCloudApp.Requests;
2021-10-12 12:17:46 +05:00
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
2023-01-26 15:37:46 +05:00
using System;
2021-10-12 12:17:46 +05:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2024-02-21 15:08:51 +05:00
namespace AsbCloudInfrastructure.Repository;
public class WellCompositeRepository<TDto> : IWellCompositeRepository
where TDto : ProcessMapPlanBaseDto
2021-10-12 12:17:46 +05:00
{
2024-02-21 15:08:51 +05:00
private readonly IAsbCloudDbContext db;
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository;
2024-02-21 15:08:51 +05:00
public WellCompositeRepository(
IAsbCloudDbContext db,
IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository)
2021-10-12 12:17:46 +05:00
{
2024-02-21 15:08:51 +05:00
this.db = db;
this.processMapPlanDrillingRepository = processMapPlanDrillingRepository;
}
2021-10-12 12:17:46 +05:00
2024-02-21 15:08:51 +05:00
/// <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);
}
2021-10-12 12:17:46 +05:00
2024-02-21 15:08:51 +05:00
/// <inheritdoc/>
public Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token)
{
db.WellComposites.RemoveRange(db.WellComposites
.Where(c => c.IdWell == idWell));
2024-02-21 15:08:51 +05:00
var entities = wellComposites
.Select(w => Convert(idWell, w));
2024-02-21 15:08:51 +05:00
db.WellComposites.AddRange(entities);
return db.SaveChangesAsync(token);
}
2024-02-21 15:08:51 +05:00
/// <inheritdoc/>
public Task<IEnumerable<ProcessMapPlanBaseDto>> GetCompositeProcessMap(int idWell, CancellationToken token)
2024-02-21 15:08:51 +05:00
{
throw new NotImplementedException();
2024-02-21 15:08:51 +05:00
}
2023-01-26 15:37:46 +05:00
2024-02-21 15:08:51 +05:00
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;
2021-10-12 12:17:46 +05:00
}
}
2024-02-21 15:08:51 +05:00