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

60 lines
1.7 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
public class DrillerService : CrudCacheServiceBase<DrillerDto, Driller>, IDrillerService
{
private IAsbCloudDbContext context;
public DrillerService(IAsbCloudDbContext db, CacheDb cacheDb) : base(db, cacheDb)
{
context= db;
}
public override async Task<int> DeleteAsync(int id, CancellationToken dto)
{
var result = await Cache.RemoveAsync(o => o.Id == id);
return result;
}
public override async Task<IEnumerable<DrillerDto>> GetAllAsync(CancellationToken token)
{
return await base.GetAllAsync(token);
}
public override async Task<DrillerDto> GetAsync(int id, CancellationToken token)
{
var res= await Cache.FirstOrDefaultAsync(o=>o.Id==id,token)
.ConfigureAwait(false);
if (res is null)
return null;
var dto = Convert(res);
return dto;
}
public override async Task<int> InsertAsync(DrillerDto dto, CancellationToken token)
{
var entity = Convert(dto);
var result = await Cache.InsertAsync(entity, token);
return result.Id;
}
public override async Task<int> UpdateAsync(int id, DrillerDto dto, CancellationToken token)
{
var entity = Convert(dto);
var result = await Cache.UpsertAsync(entity, token);
return result;
}
}
}