diff --git a/AsbCloudInfrastructure/Services/WellOperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationsStatService.cs index f670e045..23f6345f 100644 --- a/AsbCloudInfrastructure/Services/WellOperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationsStatService.cs @@ -82,18 +82,17 @@ namespace AsbCloudInfrastructure.Services public async Task GetStatClusterAsync(int idCluster, CancellationToken token = default) { - var operations = await db.WellOperations - .Where(o => o.Well.IdCluster == idCluster) - .OrderBy(o => o.StartDate) + var wells = await db.Wells + .Include(w => w.WellOperations) + .Where(o => o.IdCluster == idCluster) .AsNoTracking() .ToListAsync(token); - if (!operations.Any()) - return null; + var operations = wells.SelectMany(w => w.WellOperations).OrderBy(o => o.StartDate); var cluster = await cacheCluster.FirstOrDefaultAsync(c => c.Id == idCluster, token); - var wellsIds = operations.Select(o => o.IdWell).Distinct(); + var wellsIds = wells.Select(o => o.Id).Distinct(); var statsWells = new List(wellsIds.Count()); @@ -137,6 +136,13 @@ namespace AsbCloudInfrastructure.Services var well = await cacheWell.FirstOrDefaultAsync(w => w.Id == idWell, token); var wellType = await cacheWellType.FirstOrDefaultAsync(t => t.Id == well.IdWellType, token); + if (!wellOperations.Any()) + return new StatWellDto() + { + Caption = well.Caption, + WellType = wellType.Caption + }; + var statWellDto = new StatWellDto { Id = idWell,