DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/_CachedCrudService.cs

49 lines
1.6 KiB
C#
Raw Normal View History

2021-10-01 15:44:56 +05:00
//using AsbCloudApp.Data;
//using AsbCloudApp.Services;
//using AsbCloudDb.Model;
//using AsbCloudInfrastructure.Services.Cache;
//using Mapster;
//using Microsoft.EntityFrameworkCore;
//using System;
//using System.Linq;
//using System.Threading;
//using System.Threading.Tasks;
//namespace AsbCloudInfrastructure.Services
//{
// public class _CachedCrudService<Tdto, TModel> : ICachedCrudService<Tdto>
// where TModel : class, AsbCloudDb.Model.IId
// where Tdto : AsbCloudApp.Data.IId
// {
// private readonly CacheTable<TModel> cache;
// public _CachedCrudService(IAsbCloudDbContext db, Cache.CacheDb cacheDb)
// {
// cache = cacheDb.GetCachedTable<TModel>((DbContext)db);
// }
// public virtual async Task<PaginationContainer<Tdto>> GetAsync(int skip = 0, int take = 32, CancellationToken token = default)
// {
// var count = cache.Count();
// var result = new PaginationContainer<Tdto> { Skip = skip, Take = take, Count = count };
// if (count <= skip)
// return result;
// var items = await cache.WhereAsync(token).ConfigureAwait(false);
// result.Items.AddRange(items.OrderBy(i => i.Id).Skip(skip).Take(take).Select(i => Convert(i)));
// return result;
// }
// public virtual Task<Tdto> GetAsync(int id, CancellationToken token = default)
// {
// throw new NotImplementedException();
// }
// public virtual Tdto Convert(TModel src) => src.Adapt<Tdto>();
// public virtual TModel Convert(Tdto src) => src.Adapt<TModel>();
// }
//}