using AsbCloudApp.Data.ProcessMapPlan; 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) { var query = db .Set() .Include(e => e.Author) .Include(e => e.Editor) .Include(e => e.Well) .Where(e => e.IdWell == request.IdWell); if (request.IdWellSectionType.HasValue) query = query.Where(e => e.IdWellSectionType == request.IdWellSectionType); if (request.UpdateFrom.HasValue) { var from = request.UpdateFrom.Value.ToUniversalTime(); query = query.Where(e => e.Creation >= from || e.Obsolete >= from); } if (request.Moment.HasValue) { var moment = request.Moment.Value.ToUniversalTime(); query = query .Where(e => e.Creation <= moment) .Where(e => e.Obsolete == null || e.Obsolete >= moment); } return query; } protected override TimeSpan GetTimezoneOffset(ProcessMapPlanBaseRequestWithWell request) { var timezone = wellService.GetTimezone(request.IdWell); var offset = TimeSpan.FromHours(timezone.Hours); return offset; } }