Esempio n. 1
0
        private async Task LoadParentDetailsWithFirstChildrenAsync()
        {
            var firstGenDetails = await _detailService.GetParentDetailsAsync();

            var firstGenDetailsHierarchyIds = firstGenDetails
                                              .Select(x => x.HierarchyLevel)
                                              .ToList();


            var secondGenDetails =
                await _detailService.GetDetailsFirstDescendantsAsync(firstGenDetailsHierarchyIds);

            foreach (var firstGenDetail in firstGenDetails)
            {
                var treeNode = new TreeNode()
                {
                    Text = DetailNameInTree(firstGenDetail.Name),
                    Tag  = new DetailInTreeView()
                    {
                        DetailId       = firstGenDetail.DetailId,
                        Name           = firstGenDetail.Name,
                        HierarchyLevel = firstGenDetail.HierarchyLevel
                    },
                    Name = firstGenDetail.HierarchyLevel.ToString()
                };

                var childDetails = secondGenDetails
                                   .Where(x => x.HierarchyLevel.IsDescendantOf(firstGenDetail.HierarchyLevel))
                                   .ToList();

                foreach (var childDetail in childDetails)
                {
                    treeNode.Nodes.Add(new TreeNode()
                    {
                        Text = DetailNameInTree(childDetail.Name, childDetail.Count),
                        Tag  = new DetailInTreeView()
                        {
                            DetailId       = childDetail.DetailId,
                            Name           = childDetail.Name,
                            Count          = childDetail.Count,
                            HierarchyLevel = childDetail.HierarchyLevel
                        },
                        Name = childDetail.HierarchyLevel.ToString()
                    });
                }

                treeView.Nodes.Add(treeNode);
            }
        }