using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { public class ScheduleService : CrudCacheServiceBase, IScheduleService { private IAsbCloudDbContext context; public ScheduleService(IAsbCloudDbContext db, CacheDb cacheDb) : base(db, cacheDb) { context= db; } public override async Task DeleteAsync(int id, CancellationToken dto) { var result = await Cache.RemoveAsync(o => o.Id == id); return result; } public override async Task> GetAllAsync(CancellationToken token) { return await base.GetAllAsync(token); } public override async Task 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 async Task> GetSchedule(int idWell, DateTimeOffset dateStart, DateTimeOffset dateEnd, CancellationToken token = default) { var entires=await Cache.WhereAsync(o=>o.IdWell==idWell &&o.ShiftStart<=dateStart &&o.ShiftEnd<=dateEnd).ConfigureAwait(false); var res = entires?.Select(Convert); return res; } public override async Task InsertAsync(ScheduleDto dto, CancellationToken token) { var entity = Convert(dto); var result = await Cache.InsertAsync(entity, token); return result.Id; } public override async Task UpdateAsync(int id, ScheduleDto dto, CancellationToken token) { var entity = Convert(dto); var result = await Cache.UpsertAsync(entity, token); return result; } } }