From 7480b63ccbe5f892daea4b8bb9aead318f53adb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Mon, 3 Jul 2023 17:22:37 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6?= =?UTF-8?q?=D0=B8=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit При создании и обновлении скважины добавил проверку на то, что указанная телеметрия не принадлежит другой скважине. --- .../Services/WellService.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 7645c0aa..01f9cb32 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -126,8 +126,11 @@ namespace AsbCloudInfrastructure.Services return wells; } - public override async Task InsertAsync(WellDto dto, CancellationToken token = default) + public override async Task InsertAsync(WellDto dto, CancellationToken token) { + if (await IsExistingTelemetryAsync(dto.IdTelemetry, token)) + throw new ArgumentInvalidException("Телеметрия уже была привязана к другой скважине.", nameof(dto)); + if (dto.IdWellType is < 1 or > 2) throw new ArgumentInvalidException("Тип скважины указан неправильно.", nameof(dto)); @@ -158,8 +161,11 @@ namespace AsbCloudInfrastructure.Services } public override async Task UpdateAsync(WellDto dto, - CancellationToken token = default) + CancellationToken token) { + if (await IsExistingTelemetryAsync(dto.IdTelemetry, token)) + throw new ArgumentInvalidException("Телеметрия уже была привязана к другой скважине.", nameof(dto)); + if (dto.IdWellType is < 1 or > 2) throw new ArgumentInvalidException("Тип скважины указан неправильно.", nameof(dto)); @@ -335,6 +341,15 @@ namespace AsbCloudInfrastructure.Services throw new Exception($"Can't find timezone for well {wellDto.Caption} id: {wellDto.Id}"); } + private Task IsExistingTelemetryAsync(int? idTelemetry, CancellationToken cancellationToken) + { + if (!idTelemetry.HasValue) + return Task.FromResult(false); + + return dbSet.AnyAsync(x => x.IdTelemetry == + idTelemetry.Value, cancellationToken); + } + private static AsbCloudDb.Model.IMapPoint GetCoordinates(Well well) { if (well is null)