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 : ChangeLogRepositoryAbstract where TDto : ProcessMapPlanBaseDto where TEntity : ProcessMapPlanBase { private readonly IWellService wellService; public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService) : base(context) { this.wellService = wellService; } protected override IQueryable BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable 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; } }