2021-10-12 12:17:46 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class WellCompositeService : IWellCompositeService
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext context;
|
|
|
|
|
|
|
|
|
|
public WellCompositeService(IAsbCloudDbContext context)
|
|
|
|
|
{
|
|
|
|
|
this.context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<WellCompositeDto>> GetAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var entities = await context.WellComposites
|
|
|
|
|
.Where(c => c.IdWell == idWell)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.ToListAsync(token)
|
|
|
|
|
.ConfigureAwait(false);
|
2022-06-06 15:43:47 +05:00
|
|
|
|
return entities.Select(Convert);
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
context.WellComposites.RemoveRange(context.WellComposites
|
|
|
|
|
.Where(c => c.IdWell == idWell));
|
2021-10-14 14:46:20 +05:00
|
|
|
|
|
2021-10-12 12:17:46 +05:00
|
|
|
|
var entities = wellComposites
|
2022-06-06 15:43:47 +05:00
|
|
|
|
.Select(w => Convert(idWell, w));
|
2021-10-14 14:46:20 +05:00
|
|
|
|
|
2021-10-12 12:17:46 +05:00
|
|
|
|
context.WellComposites.AddRange(entities);
|
|
|
|
|
return context.SaveChangesAsync(token);
|
|
|
|
|
}
|
2022-06-06 15:43:47 +05:00
|
|
|
|
|
|
|
|
|
private WellComposite Convert(int idWell, WellCompositeDto dto)
|
|
|
|
|
{
|
|
|
|
|
var entity = dto.Adapt<WellComposite>();
|
|
|
|
|
entity.IdWell = idWell;
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
private WellCompositeDto Convert(WellComposite entity)
|
|
|
|
|
{
|
|
|
|
|
var dto = entity.Adapt<WellCompositeDto>();
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
|
|
|
|
}
|