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

49 lines
1.6 KiB
C#
Raw Normal View History

using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
#nullable enable
public class CrudWellRelatedCacheServiceBase<TDto, TEntity> : CrudCacheServiceBase<TDto, TEntity>, IRepositoryWellRelated<TDto>
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
where TEntity : class, IId, IWellRelated
{
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext context, IMemoryCache memoryCache)
: base(context, memoryCache) { }
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext context, IMemoryCache memoryCache, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
: base(context, memoryCache, makeQuery) { }
2022-11-16 17:07:47 +05:00
public async Task<IEnumerable<TDto>?> GetByIdWellAsync(int idWell, CancellationToken token)
{
var cache = await GetCacheAsync(token);
2022-11-16 17:07:47 +05:00
var dtos = cache
.Where(e => e.IdWell == idWell)
.ToList();
return dtos;
}
2022-11-16 17:07:47 +05:00
public async Task<IEnumerable<TDto>?> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
{
if (!idsWells.Any())
return Enumerable.Empty<TDto>();
2022-06-15 14:57:37 +05:00
var cache = await GetCacheAsync(token);
2022-11-16 17:07:47 +05:00
var dtos = cache
2022-06-15 14:57:37 +05:00
.Where(e => idsWells.Contains(e.IdWell))
.ToList();
return dtos;
}
}
#nullable disable
}