2024-07-04 11:02:45 +05:00
|
|
|
using AsbCloudApp.Services;
|
2022-06-09 11:19:52 +05:00
|
|
|
using AsbCloudDb.Model;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-11-17 16:09:51 +05:00
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
2022-06-09 11:19:52 +05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
2023-04-18 16:22:53 +05:00
|
|
|
|
2022-06-09 11:19:52 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
public class CrudWellRelatedCacheRepositoryBase<TDto, TEntity> : CrudCacheRepositoryBase<TDto, TEntity>, IRepositoryWellRelated<TDto>
|
|
|
|
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
|
|
|
|
where TEntity : class, IId, IWellRelated
|
|
|
|
{
|
|
|
|
public CrudWellRelatedCacheRepositoryBase(IAsbCloudDbContext context, IMemoryCache memoryCache)
|
|
|
|
: base(context, memoryCache) { }
|
|
|
|
|
|
|
|
public CrudWellRelatedCacheRepositoryBase(IAsbCloudDbContext context, IMemoryCache memoryCache, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
|
|
|
|
: base(context, memoryCache, makeQuery) { }
|
2022-06-09 11:19:52 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
public async Task<IEnumerable<TDto>> GetByIdWellAsync(int idWell, CancellationToken token)
|
|
|
|
{
|
|
|
|
var cache = await GetCacheAsync(token);
|
2022-06-16 12:33:05 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
var dtos = cache
|
|
|
|
.Where(e => e.IdWell == idWell)
|
|
|
|
.Select(Convert);
|
2022-06-16 12:33:05 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
return dtos;
|
|
|
|
}
|
2022-06-09 11:19:52 +05:00
|
|
|
|
2024-08-19 10:01:07 +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
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
var cache = await GetCacheAsync(token);
|
2022-06-16 12:33:05 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
var dtos = cache
|
|
|
|
.Where(e => idsWells.Contains(e.IdWell))
|
|
|
|
.Select(Convert);
|
2022-12-05 09:36:02 +05:00
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
return dtos;
|
2022-06-09 11:19:52 +05:00
|
|
|
}
|
2022-06-16 12:33:05 +05:00
|
|
|
}
|