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

47 lines
1.6 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.Repository
{
public class CrudWellRelatedRepositoryBase<TDto, TEntity> : CrudRepositoryBase<TDto, TEntity>, IRepositoryWellRelated<TDto>
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
where TEntity : class, IId, IWellRelated
{
public CrudWellRelatedRepositoryBase(IAsbCloudDbContext context)
: base(context) { }
public CrudWellRelatedRepositoryBase(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)
.AsNoTracking()
.ToArrayAsync(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))
.AsNoTracking()
.ToArrayAsync(token);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
}
}