private void GenerateNodeChildren(IEnumerable <TreeSiblings> siblings) { var immediateChildIds = new List <int>(); foreach (var taskParent in siblings) { immediateChildIds.AddRange(GetAllChildren(taskParent.Node.TaskConfigurationId)); if (immediateChildIds.Any()) { var children = _allSources.Where(x => x.TaskConfigGroupId == immediateChildIds.First()).ToList(); foreach (var child in children) { var lvl2Children = new TreeSiblings { Depth = taskParent.Depth + 1, TaskParent = taskParent, Children = new List <TreeSiblings>(), Node = child }; taskParent.Children.Add(lvl2Children); } } immediateChildIds.Clear(); GenerateNodeChildren(taskParent.Children); } }
private void DeleteSiblingNode(TreeSiblings sibling) { if (sibling.Children.Any()) { if (ChildNodeWarning(sibling.Node.TaskConfiguration.Title) == DialogResult.Yes) { _viewModel.DeleteTreeNode(sibling.Node.TaskConfigurationId, sibling.Children); } } else { _viewModel.DeleteTreeNode(sibling.Node.TaskConfigurationId, new List <TreeSiblings> { sibling }); } }
public List <TreeParent> PopulateTree() { using (var ctx = new PureDataContext(DevDb)) { _allGroups = ctx.Set <TaskConfigGroup>() .Include(x => x.CaseState) .Include(x => x.TaskConfigSources) .ToList(); _allSources = ctx.Set <TaskConfigSource>() .Include(x => x.TaskConfigGroup) .Include(x => x.TaskConfiguration) .ToList(); } var rootParentConfigGroups = _allGroups.Where(x => x.ParentTaskConfigId == null).ToList(); var rootParents = new List <TreeParent>(); foreach (var rootParent in rootParentConfigGroups) { var caseState = new TreeParent { CaseState = rootParent.CaseState, Children = new List <TreeSiblings>() }; foreach (var source in rootParent.TaskConfigSources.ToList()) { var lvl1Children = new TreeSiblings { Depth = rootParent.Depth, CaseParent = caseState, Node = source, Children = new List <TreeSiblings>() }; caseState.Children.Add(lvl1Children); } GenerateNodeChildren(caseState.Children); rootParents.Add(caseState); } return(rootParents); }
public void BuildCaseState1OfferBranch() { var offer = _allGroups.SingleOrDefault(x => x.ParentCaseStateId == 1 && x.ParentTaskConfigId == null); var rootParent = new TreeParent { CaseState = offer?.CaseState, Children = new List <TreeSiblings>() }; foreach (var source in offer.TaskConfigSources.ToList()) { var lvl1Children = new TreeSiblings { Depth = offer.Depth, CaseParent = rootParent, Node = source, Children = new List <TreeSiblings>() }; rootParent.Children.Add(lvl1Children); } var immediateChildIds = new List <int>(); //1. find the ids off the immediate children from the parent case group. foreach (var taskParent in rootParent.Children) { immediateChildIds.AddRange(GetAllChildren(taskParent.Node.TaskConfigurationId)); if (immediateChildIds.Any()) { var children = _allSources.Where(x => x.TaskConfigGroupId == immediateChildIds.First()).ToList(); //2. Use the ids to gather a list of the next layer of children. foreach (var child in children) { var lvl2Children = new TreeSiblings { Depth = taskParent.Depth + 1, TaskParent = taskParent, Children = new List <TreeSiblings>(), Node = child }; taskParent.Children.Add(lvl2Children); } } immediateChildIds.Clear(); } foreach (var taskSuperParent in rootParent.Children) { foreach (var taskParent in taskSuperParent.Children) { immediateChildIds.AddRange(GetAllChildren(taskParent.Node.TaskConfigurationId)); if (immediateChildIds.Any()) { var children = _allSources.Where(x => x.TaskConfigGroupId == immediateChildIds.First()).ToList(); //2. Use the ids to gather a list of the next layer of children. foreach (var child in children) { var lvl3Children = new TreeSiblings { Depth = taskParent.Depth + 1, TaskParent = taskParent, Children = new List <TreeSiblings>(), Node = child }; taskParent.Children.Add(lvl3Children); } } immediateChildIds.Clear(); } } }
public CaseState GetRootParent(TreeSiblings sibling) { return(sibling.TaskParent != null?GetRootParent(sibling.TaskParent) : sibling.CaseParent.CaseState); }