Правка по результата ревью

This commit is contained in:
Olga Nemt 2024-07-26 16:19:24 +05:00
parent 2bf247b78e
commit e525e05584
2 changed files with 13 additions and 10 deletions

View File

@ -62,11 +62,11 @@ namespace AsbCloudApp.Services
Task<int> DeleteAsync(int idWell, int id, CancellationToken token); Task<int> DeleteAsync(int idWell, int id, CancellationToken token);
/// <summary> /// <summary>
/// Перенос контактов из скважины на скважину /// Скопировать контакты в другую скважину
/// </summary> /// </summary>
/// <param name="idWell">ключ текущей скважины</param> /// <param name="idWell">ключ скважины, откуда копировать контакты</param>
/// <param name="idWellTarget">ключ новой скважины</param> /// <param name="idWellTarget">ключ скважины, куда копировать контакты</param>
/// <param name="contactIds">ключи контактов</param> /// <param name="contactIds"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> CopyAsync(int idWell, int idWellTarget, IEnumerable<int> contactIds, CancellationToken token); Task<int> CopyAsync(int idWell, int idWellTarget, IEnumerable<int> contactIds, CancellationToken token);

View File

@ -92,17 +92,20 @@ namespace AsbCloudInfrastructure.Services
public async Task<int> CopyAsync(int idWell, int idWellTarget, IEnumerable<int> contactIds, CancellationToken token) public async Task<int> CopyAsync(int idWell, int idWellTarget, IEnumerable<int> contactIds, CancellationToken token)
{ {
var newContacts = await GetContacts(idWell, contactIds, token); var contacts = await GetContacts(idWell, contactIds, token);
if (!newContacts.Any()) if (!contacts.Any())
throw new ForbidException("contacts not found"); return 0;
foreach (var newContact in newContacts) var newContacts = contacts.Select(contact =>
{ {
var newContact = contact.Adapt<Contact>();
newContact.IdWell = idWellTarget; newContact.IdWell = idWellTarget;
newContact.Id = default; newContact.Id = default;
}
await db.Contacts.AddRangeAsync(newContacts); return newContact;
});
db.Contacts.AddRange(newContacts);
return await db.SaveChangesAsync(token); return await db.SaveChangesAsync(token);
} }