private void UpdateAuthorRelationship(int bookCod, List <Author> newAuthors, List <Author> oldAuthors) { if (bookCod <= 0) { return; } List <Author> authorsToAdd = newAuthors .Where(n => !oldAuthors .Any(o => o.AuthorCod == n.AuthorCod)) .ToList(); if (authorsToAdd.Any()) { _authorRepository.AddManyRelations(bookCod, authorsToAdd); } List <Author> authorsToRemove = oldAuthors .Where(o => !newAuthors .Any(n => n.AuthorCod == o.AuthorCod)) .ToList(); if (authorsToRemove.Any()) { _authorRepository.DeleteManyRelations(bookCod, authorsToRemove); } }