public IActionResult GetDataToNode(string filter = "") { // condition //Expression<Func<TblTrainingType, bool>> condition = e => e.TrainingTypeParentId == null || e.TrainingTypeParentId < 1; var HasData = new List <TreeNodeViewModel <TblTrainingType> >(); foreach (var data in this.repository.GetAllWithRelateAsync(null).Result) { if (data.TrainingTypeParentId != null || data?.TrainingTypeParentId < 1) { continue; } var newTree = new TreeNodeViewModel <TblTrainingType>(data); if (data.InverseTrainingTypeParent != null) { foreach (var node in data.InverseTrainingTypeParent) { var newNode = new TreeNodeViewModel <TblTrainingType>(node); if (node.InverseTrainingTypeParent != null) { foreach (var subNode in node.InverseTrainingTypeParent) { newNode.AddChild(new TreeNodeViewModel <TblTrainingType>(subNode)); } } newNode.data.InverseTrainingTypeParent = null; newTree.AddChild(newNode); } } newTree.data.InverseTrainingTypeParent = null; HasData.Add(newTree); } return(new JsonResult(HasData, this.DefaultJsonSettings)); }