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 async Task <IActionResult> TopicTree() { var response = await _getTopicTreeOperation.Execute(); var model = new TopicTreeModel(response); return(Ok(model)); }