DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/ProcessMapWellboreDevelopmentRepository.cs
Степанов Дмитрий ed16b7e374 Рефакторинг
Сделан рефакторинг: сервиса, репозитория, контроллера
2023-09-26 14:31:37 +05:00

46 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMap;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Repository;
public class ProcessMapWellboreDevelopmentRepository :
CrudWellRelatedRepositoryBase<ProcessMapWellboreDevelopmentDto, ProcessMapWellboreDevelopment>,
IProcessMapWellboreDevelopmentRepository
{
private readonly IWellService wellService;
public ProcessMapWellboreDevelopmentRepository(IAsbCloudDbContext context, IWellService wellService) : base(context)
{
this.wellService = wellService;
}
public async Task<IEnumerable<ProcessMapWellboreDevelopmentDto>> GetAllAsync(int idWell, DateTime? updateFrom,
CancellationToken cancellationToken)
{
var query = dbContext.ProcessMapWellboreDevelopments
.Where(p => p.IdWell == idWell);
if (updateFrom.HasValue)
{
var timezone = wellService.GetTimezone(idWell);
var updateFromUtc = updateFrom.Value.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(p => p.LastUpdate >= updateFromUtc);
}
var entities = await query
.OrderBy(p => p.DepthStart)
.ThenBy(p => p.Id)
.AsNoTracking()
.ToArrayAsync(cancellationToken);
return entities.Select(Convert);
}
}