приведение дат в фильтре для поиска к корректному значению.

Метод GetListAsync
This commit is contained in:
eugeniy_ivanov 2022-10-29 20:28:55 +05:00
parent 25cd263598
commit 98c60a0d86

View File

@ -32,18 +32,42 @@ namespace AsbCloudInfrastructure.Services.DailyReport
public async Task<IEnumerable<DailyReportDto>> GetListAsync(int idWell, DateTime? begin, DateTime? end, CancellationToken token) public async Task<IEnumerable<DailyReportDto>> GetListAsync(int idWell, DateTime? begin, DateTime? end, CancellationToken token)
{ {
var well = wellService.GetOrDefault(idWell);
if (well is null || well.Timezone is null)
return null;
var query = db.DailyReports.Where(r => r.IdWell == idWell); var query = db.DailyReports.Where(r => r.IdWell == idWell);
if (begin is not null) if (begin is not null)
query = query.Where(d => d.StartDate >= begin.Value.Date); {
DateTimeOffset beginUTC = begin.Value
.AddHours(5)
.ToUtcDateTimeOffset(well.Timezone.Hours);
query = query.Where(d => d.StartDate >= beginUTC);
}
if (end is not null) if (end is not null)
query = query.Where(d => d.StartDate <= end.Value.Date); {
DateTimeOffset endUTC = end.Value
.AddHours(5)
.ToUtcDateTimeOffset(well.Timezone.Hours);
query = query.Where(d => d.StartDate <= endUTC);
}
var entities = await query var entities = await query
.ToListAsync(token); .ToListAsync(token);
return entities.Select(r => Convert(r)); return entities.Select(r => Convert(r));
//var query = db.DailyReports.Where(r => r.IdWell == idWell);
//if (begin is not null)
// query = query.Where(d => d.StartDate >= begin.Value.Date);
//if (end is not null)
// query = query.Where(d => d.StartDate <= end.Value.Date);
//var entities = await query
// .ToListAsync(token);
//return entities.Select(r => Convert(r));
} }
public async Task<DailyReportDto> GetOrGenerateAsync(int idWell, DateTime date, CancellationToken token) public async Task<DailyReportDto> GetOrGenerateAsync(int idWell, DateTime date, CancellationToken token)