DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs

60 lines
1.8 KiB
C#

using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMapPlan;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
namespace AsbCloudInfrastructure.Repository;
public class ProcessMapPlanBaseRepository<TEntity, TDto> : ChangeLogRepositoryAbstract<TEntity, TDto, ProcessMapPlanBaseRequestWithWell>
where TDto : ProcessMapPlanBaseDto
where TEntity : ProcessMapPlanBase
{
private readonly IWellService wellService;
public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context)
{
this.wellService = wellService;
}
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable<TEntity> query)
{
query = query
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
if (request.UpdateFrom.HasValue)
{
var from = request.UpdateFrom.Value.ToUniversalTime();
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
}
return query;
}
protected override TimeSpan GetTimezoneOffset(ProcessMapPlanBaseRequestWithWell request)
{
var timezone = wellService.GetTimezone(request.IdWell);
var offset = TimeSpan.FromHours(timezone.Hours);
return offset;
}
protected override TDto Convert(TEntity entity, TimeSpan offset)
{
var dto = base.Convert(entity, offset);
dto.Section = entity.WellSectionType.Caption;
return dto;
}
protected override TEntity Convert(TDto dto)
{
var entity = base.Convert(dto);
return entity;
}
}