forked from ddrilling/AsbCloudServer
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using Mapster;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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);
|
|
return entities.Adapt<WellCompositeDto>();
|
|
}
|
|
|
|
public Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token)
|
|
{
|
|
context.WellComposites.RemoveRange(context.WellComposites
|
|
.Where(c => c.IdWell == idWell));
|
|
var entities = wellComposites
|
|
.Adapt<WellComposite>(s => s.IdWell = idWell);
|
|
context.WellComposites.AddRange(entities);
|
|
return context.SaveChangesAsync(token);
|
|
}
|
|
}
|
|
}
|