forked from ddrilling/AsbCloudServer
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
{
|
|
#nullable enable
|
|
public class CrudWellRelatedServiceBase<TDto, TEntity> : CrudServiceBase<TDto, TEntity>, ICrudWellRelatedService<TDto>
|
|
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
|
|
where TEntity : class, AsbCloudDb.Model.IId, AsbCloudDb.Model.IWellRelated
|
|
{
|
|
public CrudWellRelatedServiceBase(IAsbCloudDbContext context)
|
|
: base(context) { }
|
|
|
|
public CrudWellRelatedServiceBase(IAsbCloudDbContext dbContext, ISet<string> includes)
|
|
: base(dbContext, includes) { }
|
|
|
|
public CrudWellRelatedServiceBase(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
|
|
: base(context, makeQuery) { }
|
|
|
|
public async Task<IEnumerable<TDto>> GetByIdWellAsync(int idWell, CancellationToken token)
|
|
{
|
|
var entities = await GetQuery()
|
|
.Where(e => e.IdWell == idWell)
|
|
.ToListAsync(token);
|
|
var dtos = entities.Select(Convert).ToList();
|
|
return dtos;
|
|
}
|
|
|
|
public async Task<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
|
|
{
|
|
if (!idsWells.Any())
|
|
return Enumerable.Empty<TDto>();
|
|
|
|
var entities = await GetQuery()
|
|
.Where(e => idsWells.Contains(e.IdWell))
|
|
.ToListAsync(token);
|
|
var dtos = entities.Select(Convert).ToList();
|
|
return dtos;
|
|
}
|
|
}
|
|
#nullable disable
|
|
}
|