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

60 lines
1.9 KiB
C#
Raw Normal View History

2024-01-19 17:48:45 +05:00
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<TDto, TEntity> : ChangeLogRepositoryAbstract<TDto, TEntity, ProcessMapPlanBaseRequestWithWell>
2024-01-19 17:48:45 +05:00
where TDto : ProcessMapPlanBaseDto
where TEntity : ProcessMapPlanBase
{
private readonly IWellService wellService;
public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context)
2024-01-19 17:48:45 +05:00
{
this.wellService = wellService;
}
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request)
2024-01-19 17:48:45 +05:00
{
var query = db
2024-01-19 17:48:45 +05:00
.Set<TEntity>()
.Include(e => e.Author)
.Include(e => e.Editor)
.Include(e => e.Well)
.Where(e => e.IdWell == request.IdWell);
2024-01-19 17:48:45 +05:00
if (request.IdWellSectionType.HasValue)
2024-01-19 17:48:45 +05:00
query = query.Where(e => e.IdWellSectionType == request.IdWellSectionType);
if (request.UpdateFrom.HasValue)
{
var from = request.UpdateFrom.Value.ToUniversalTime();
2024-01-20 15:38:37 +05:00
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
2024-01-19 17:48:45 +05:00
}
if (request.Moment.HasValue)
{
var moment = request.Moment.Value.ToUniversalTime();
query = query
2024-01-21 09:38:07 +05:00
.Where(e => e.Creation <= moment)
.Where(e => e.Obsolete == null || e.Obsolete >= moment);
2024-01-19 17:48:45 +05:00
}
return query;
2024-01-19 17:48:45 +05:00
}
protected override TimeSpan GetTimezoneOffset(ProcessMapPlanBaseRequestWithWell request)
2024-01-19 17:48:45 +05:00
{
var timezone = wellService.GetTimezone(request.IdWell);
2024-01-19 17:48:45 +05:00
var offset = TimeSpan.FromHours(timezone.Hours);
return offset;
}
2024-01-19 17:48:45 +05:00
}