2022-06-09 11:19:52 +05:00
|
|
|
|
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;
|
|
|
|
|
|
2022-06-16 12:33:05 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
2022-06-09 11:19:52 +05:00
|
|
|
|
{
|
|
|
|
|
#nullable enable
|
2022-08-11 13:55:36 +05:00
|
|
|
|
public class CrudWellRelatedCacheServiceBase<TDto, TEntity> : CrudCacheServiceBase<TDto, TEntity>, IRepositoryWellRelated<TDto>
|
2022-06-09 11:19:52 +05:00
|
|
|
|
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
|
2022-06-16 12:33:05 +05:00
|
|
|
|
where TEntity : class, IId, IWellRelated
|
2022-06-09 11:19:52 +05:00
|
|
|
|
{
|
2022-06-16 12:33:05 +05:00
|
|
|
|
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext context)
|
2022-06-09 11:19:52 +05:00
|
|
|
|
: base(context) { }
|
|
|
|
|
|
2022-06-16 12:33:05 +05:00
|
|
|
|
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext dbContext, ISet<string> includes)
|
2022-06-09 11:19:52 +05:00
|
|
|
|
: base(dbContext, includes) { }
|
|
|
|
|
|
2022-06-16 12:33:05 +05:00
|
|
|
|
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
|
2022-06-09 11:19:52 +05:00
|
|
|
|
: base(context, makeQuery) { }
|
|
|
|
|
|
2022-06-14 15:35:31 +05:00
|
|
|
|
public async Task<IEnumerable<TDto>> GetByIdWellAsync(int idWell, CancellationToken token)
|
2022-06-09 11:19:52 +05:00
|
|
|
|
{
|
2022-06-16 12:33:05 +05:00
|
|
|
|
var cache = await GetCacheAsync(token);
|
|
|
|
|
|
|
|
|
|
var dtos = cache.Values
|
|
|
|
|
.Where(e => e.IdWell == idWell)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2022-06-09 11:19:52 +05:00
|
|
|
|
return dtos;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 15:35:31 +05:00
|
|
|
|
public async Task<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
|
2022-06-09 11:19:52 +05:00
|
|
|
|
{
|
|
|
|
|
if (!idsWells.Any())
|
|
|
|
|
return Enumerable.Empty<TDto>();
|
2022-06-15 14:57:37 +05:00
|
|
|
|
|
2022-06-16 12:33:05 +05:00
|
|
|
|
var cache = await GetCacheAsync(token);
|
|
|
|
|
|
|
|
|
|
var dtos = cache.Values
|
2022-06-15 14:57:37 +05:00
|
|
|
|
.Where(e => idsWells.Contains(e.IdWell))
|
2022-06-16 12:33:05 +05:00
|
|
|
|
.ToList();
|
2022-06-09 11:19:52 +05:00
|
|
|
|
return dtos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#nullable disable
|
2022-06-16 12:33:05 +05:00
|
|
|
|
}
|