private async Task EnsureNewParentIsNotChild(Guid topicToUpdateId, Guid newParent) { var tree = await _getTopicTreeOperation.Execute(); GetTopicTreeOperationResponse.Topic topicToUpdate = null; foreach (var treeRoot in tree.Roots) { topicToUpdate = treeRoot .FindAnyOrDefault( root => root.Children, topic => topic.Id == topicToUpdateId); if (topicToUpdate != null) { break; } } bool newParentIsChild = topicToUpdate.FindAnyOrDefault( root => root.Children, topic => topic.Id == newParent) != null; if (newParentIsChild) { throw new ApplicationException("Cannot assign a child topic as a parent."); } }
public TopicTreeNode(GetTopicTreeOperationResponse.Topic topic) { Id = topic.Id; Name = topic.Subject; Children = topic.Children.Select(c => new TopicTreeNode(c)).ToList(); }