diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs
index 0409969e..d37a1e90 100644
--- a/AsbCloudApp/Repositories/IWellOperationRepository.cs
+++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs
@@ -54,7 +54,7 @@ namespace AsbCloudApp.Repositories
///
/// Обновить существующую операцию
///
- ///
+ ///
///
///
Task UpdateRangeAsync(IEnumerable dtos, CancellationToken token);
diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
index bdbd1f0c..9bcc718b 100644
--- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
+++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
@@ -72,15 +72,15 @@ public class WellOperationRepository : CrudRepositoryBase> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
{
- var query = BuildQuery(request, token);
- var entities = (await query)
+ var query = BuildQuery(request);
+ var entities = await query
.Select(o => new
{
o.IdCategory,
DurationMinutes = o.DurationHours * 60,
DurationDepth = o.DepthEnd - o.DepthStart
})
- .ToArray();
+ .ToArrayAsync(token);
var parentRelationDictionary = wellOperationCategoryRepository.Get(true)
.ToDictionary(c => c.Id, c => new
@@ -220,38 +220,39 @@ public class WellOperationRepository : CrudRepositoryBase(T entities, WellOperationRequest request)
- where T : IQueryable, IEnumerable
+ private static IQueryable FilterByRequest(IQueryable entities, WellOperationRequest request)
{
if (request.OperationType.HasValue)
- entities = (T)entities.Where(e => e.IdType == request.OperationType.Value);
+ entities = entities.Where(e => e.IdType == request.OperationType.Value);
if (request.SectionTypeIds?.Any() is true)
- entities = (T)entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType));
+ entities = entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType));
if (request.OperationCategoryIds?.Any() is true)
- entities = (T)entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory));
+ entities = entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory));
if (request.GeDepth.HasValue)
- entities = (T)entities.Where(e => e.DepthEnd >= request.GeDepth.Value);
+ entities = entities.Where(e => e.DepthEnd >= request.GeDepth.Value);
if (request.LeDepth.HasValue)
- entities = (T)entities.Where(e => e.DepthEnd <= request.LeDepth.Value);
+ entities = entities.Where(e => e.DepthEnd <= request.LeDepth.Value);
if (request.GeDate.HasValue)
{
var geDateUtc = request.GeDate.Value.UtcDateTime;
- entities = (T)entities.Where(e => e.DateStart >= geDateUtc);
+ entities = entities.Where(e => e.DateStart >= geDateUtc);
}
if (request.LeDate.HasValue)
{
var leDateUtc = request.LeDate.Value.UtcDateTime;
- entities = (T)entities.Where(e => e.DateStart <= leDateUtc);
+ entities = entities.Where(e => e.DateStart <= leDateUtc);
}
if (request.SortFields?.Any() is true)
- entities = (T)entities.AsQueryable().SortBy(request.SortFields);
+ entities = entities.AsQueryable().SortBy(request.SortFields);
+ else
+ entities = entities.AsQueryable().OrderBy(e => e.DateStart);
return entities;
}
- private async Task> BuildQuery(WellOperationRequest request, CancellationToken token)
+ private IQueryable BuildQuery(WellOperationRequest request)
{
var query = GetQuery()
.Where(e => request.IdsWell.Contains(e.IdWell))
@@ -328,7 +329,7 @@ public class WellOperationRepository : CrudRepositoryBase GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperations/WellOperationControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperations/WellOperationControllerTest.cs
index 006379d2..13ed2fbc 100644
--- a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperations/WellOperationControllerTest.cs
+++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperations/WellOperationControllerTest.cs
@@ -202,12 +202,12 @@ public class WellOperationControllerTest : BaseIntegrationTest
var entity2 = entity1.Adapt();
entity2.DateStart = entity2.DateStart.AddDays(1);
- entity2.IdCategory = WellOperationCategory.IdNonProductiveTime;
+ entity2.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
entity2.DurationHours = 2;
var entity3 = entity2.Adapt();
entity3.DateStart = entity3.DateStart.AddDays(1);
- entity3.IdCategory = WellOperationCategory.IdNonProductiveTime;
+ entity3.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
entity3.DurationHours = 3;
dbContext.WellOperations.Add(entity1);
@@ -216,19 +216,19 @@ public class WellOperationControllerTest : BaseIntegrationTest
await dbContext.SaveChangesAsync();
-
var request = new WellOperationRequestBase
{
OperationType = WellOperation.IdOperationTypePlan,
Skip = pageIndex,
Take = pageSize,
- };
+ SortFields = [nameof(WellOperation.DateStart)]
+ };
//act
var response = await client.GetPageOperationsAsync(well.Id, request);
//assert
- Assert.Equal(response.StatusCode, HttpStatusCode.OK);
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
var items = response.Content.Items.ToArray();