From 2746c9472933d90fb38e7280b616d4211d849b50 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 2 Feb 2023 16:07:41 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20GetMessagesAsyn?= =?UTF-8?q?c=20=D0=B2=20MessageService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/SAUB/MessageService.cs | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/AsbCloudInfrastructure/Services/SAUB/MessageService.cs b/AsbCloudInfrastructure/Services/SAUB/MessageService.cs index ce7606ff..d7540576 100644 --- a/AsbCloudInfrastructure/Services/SAUB/MessageService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/MessageService.cs @@ -28,16 +28,8 @@ namespace AsbCloudInfrastructure.Services.SAUB public async Task> GetMessagesAsync(MessageRequest request, CancellationToken token) { - var idWell = request.IdWell; - var categoryids = request.Categoryids; - var searchString = request.SearchString; - var begin = request.Begin; - var end = request.End; - var skip = request.Skip ?? 0; - var take = request.Take ?? 32; - var sortFields = request.SortFields; - var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell); + var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(request.IdWell); if (idTelemetry is null) return null; @@ -50,13 +42,13 @@ namespace AsbCloudInfrastructure.Services.SAUB var query = db.TelemetryMessages.Where(m => m.IdTelemetry == idTelemetry) .OrderBy(m => m.DateTime).AsNoTracking(); - if (categoryids?.Any() == true || !string.IsNullOrEmpty(searchString)) + if (request.Categoryids?.Any() == true || !string.IsNullOrEmpty(request.SearchString)) { - if (!string.IsNullOrEmpty(searchString)) - events = events.Where(e => e.MessageTemplate.Contains(searchString, StringComparison.OrdinalIgnoreCase)); + if (!string.IsNullOrEmpty(request.SearchString)) + events = events.Where(e => e.MessageTemplate.Contains(request.SearchString, StringComparison.OrdinalIgnoreCase)); - if (categoryids?.Any() == true) - events = events.Where(e => categoryids.ToList().Contains(e.IdCategory)); + if (request.Categoryids?.Any() == true) + events = events.Where(e => request.Categoryids.ToList().Contains(e.IdCategory)); var eventIds = events.Select(e => e.IdEvent); @@ -70,31 +62,31 @@ namespace AsbCloudInfrastructure.Services.SAUB var timezone = telemetryService.GetTimezone(idTelemetry ?? default); - if (begin != default) + if (request.Begin != default) { - var beginUtc = begin.Value.ToUtcDateTimeOffset(timezone.Hours); + var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezone.Hours); query = query.Where(m => m.DateTime >= beginUtc); } - if (end != default) + if (request.End != default) { - var endUtc = end.Value.ToUtcDateTimeOffset(timezone.Hours); + var endUtc = request.End.Value.ToUtcDateTimeOffset(timezone.Hours); query = query.Where(m => m.DateTime <= endUtc); } var result = new PaginationContainer { - Skip = skip, - Take = take, + Skip = request.Skip ?? 0, + Take = request.Take ?? 32, Count = query.Count() }; - if (sortFields?.Any() == true) + if (request.SortFields?.Any() == true) { query = query.SortBy(request.SortFields); } - var messagesList = await query.Skip(skip) - .Take(take).AsNoTracking() + var messagesList = await query.Skip(request.Skip ?? 0) + .Take(request.Take ?? 32).AsNoTracking() .ToListAsync(token).ConfigureAwait(false); if (messagesList.Count == 0)