From 7d9d248bcb3edfe03e36c872cc66045c9fa5ed96 Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Thu, 12 Jan 2023 10:32:54 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BC=D0=B5=D1=87=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IPlannedTrajectoryService.cs | 4 ++-- .../PlannedTrajectory/PlannedTrajectoryService.cs | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/AsbCloudApp/Services/IPlannedTrajectoryService.cs b/AsbCloudApp/Services/IPlannedTrajectoryService.cs index d6541fcc..31fc1130 100644 --- a/AsbCloudApp/Services/IPlannedTrajectoryService.cs +++ b/AsbCloudApp/Services/IPlannedTrajectoryService.cs @@ -21,11 +21,11 @@ namespace AsbCloudApp.Services Task> GetAsync(int idWell, CancellationToken token); /// - /// Добавить строки с координатами + /// Добавить строки с координатами по одной скважине. Если в коллекции координаты для разных скважин получаем exception. /// /// /// - /// + /// количество записанных строк или exception с описанием Task AddRangeAsync(IEnumerable plannedTrajectoryRows, CancellationToken token); /// diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs index 965b653a..7466cde3 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs @@ -24,8 +24,10 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory } /// public async Task AddRangeAsync(IEnumerable plannedTrajectoryRows, CancellationToken token) - { + { var idWell = plannedTrajectoryRows.First().IdWell; + if (!plannedTrajectoryRows.All(r => r.IdWell == idWell)) + throw new ArgumentInvalidException("Все строки должны относиться к одной скважине", nameof(plannedTrajectoryRows)); var offsetHours = wellService.GetTimezone(idWell).Hours; var entitys = plannedTrajectoryRows .Select(e => Convert(e, offsetHours)); @@ -73,9 +75,9 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory public async Task> GetAsync(int idWell, CancellationToken token) { var well = wellService.GetOrDefault(idWell); - var offsetHours = wellService.GetTimezone(idWell).Hours; if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + var offsetHours = well.Timezone.Hours; var query = db.PlannedTrajectories .AsNoTracking() .Where(x => x.IdWell == idWell); @@ -89,8 +91,9 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory /// public async Task UpdateAsync(PlannedTrajectoryDto row, CancellationToken token) - { - var entity = Convert(row, row.Id); + { + var offsetHours = wellService.GetTimezone(row.IdWell).Hours; + var entity = Convert(row, offsetHours); db.PlannedTrajectories.Update(entity); return await db.SaveChangesAsync(token) .ConfigureAwait(false);