From e525e05584fe3af5aea6680a76179d7c006f91a0 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 26 Jul 2024 16:19:24 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IWellContactService.cs | 8 ++++---- .../Services/WellContactService.cs | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/AsbCloudApp/Services/IWellContactService.cs b/AsbCloudApp/Services/IWellContactService.cs index a584fad7..266da573 100644 --- a/AsbCloudApp/Services/IWellContactService.cs +++ b/AsbCloudApp/Services/IWellContactService.cs @@ -62,11 +62,11 @@ namespace AsbCloudApp.Services Task DeleteAsync(int idWell, int id, CancellationToken token); /// - /// Перенос контактов из скважины на скважину + /// Скопировать контакты в другую скважину /// - /// ключ текущей скважины - /// ключ новой скважины - /// ключи контактов + /// ключ скважины, откуда копировать контакты + /// ключ скважины, куда копировать контакты + /// /// /// Task CopyAsync(int idWell, int idWellTarget, IEnumerable contactIds, CancellationToken token); diff --git a/AsbCloudInfrastructure/Services/WellContactService.cs b/AsbCloudInfrastructure/Services/WellContactService.cs index 7e628e9e..1bb45b77 100644 --- a/AsbCloudInfrastructure/Services/WellContactService.cs +++ b/AsbCloudInfrastructure/Services/WellContactService.cs @@ -92,17 +92,20 @@ namespace AsbCloudInfrastructure.Services public async Task CopyAsync(int idWell, int idWellTarget, IEnumerable contactIds, CancellationToken token) { - var newContacts = await GetContacts(idWell, contactIds, token); - if (!newContacts.Any()) - throw new ForbidException("contacts not found"); + var contacts = await GetContacts(idWell, contactIds, token); + if (!contacts.Any()) + return 0; - foreach (var newContact in newContacts) + var newContacts = contacts.Select(contact => { + var newContact = contact.Adapt(); newContact.IdWell = idWellTarget; newContact.Id = default; - } - await db.Contacts.AddRangeAsync(newContacts); + return newContact; + }); + + db.Contacts.AddRange(newContacts); return await db.SaveChangesAsync(token); }