forked from ddrilling/AsbCloudServer
70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
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<ScheduleDto, ScheduleItem>, IScheduleService
|
|
{
|
|
|
|
private IAsbCloudDbContext context;
|
|
|
|
public ScheduleService(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<ScheduleDto>> GetAllAsync(CancellationToken token)
|
|
{
|
|
return await base.GetAllAsync(token);
|
|
}
|
|
|
|
public override async Task<ScheduleDto> 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<IEnumerable<ScheduleDto>> 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<int> InsertAsync(ScheduleDto 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, ScheduleDto dto, CancellationToken token)
|
|
{
|
|
var entity = Convert(dto);
|
|
var result = await Cache.UpsertAsync(entity, token);
|
|
return result;
|
|
}
|
|
|
|
|
|
}
|
|
}
|