Ejemplo n.º 1
0
        private async Task DeleteDetailAsync(TreeNode selectedNode)
        {
            List <HierarchyId> removedRelations = null;

            var selectedNodeTag = selectedNode.Tag as DetailInTreeView;

            var parentNode = selectedNode.Parent;

            if (parentNode != null)
            {
                var parentNodeTag = parentNode.Tag as DetailInTreeView;

                removedRelations = await _detailService
                                   .DeleteDetailWithDescendantsAsync(
                    selectedNodeTag.DetailId,
                    parentNodeTag.DetailId);
            }

            if (parentNode == null)
            {
                removedRelations = await _detailService
                                   .DeleteDetailWithDescendantsAsync(
                    selectedNodeTag.DetailId,
                    null);
            }

            removedRelations.ForEach(removedHierarchyId =>
            {
                var nodeToRemove = treeView.Nodes
                                   .Find(removedHierarchyId.ToString(), true)
                                   .SingleOrDefault();

                if (nodeToRemove != null)
                {
                    treeView.Nodes.Remove(nodeToRemove);
                }
            });

            ShowMessageDialog("Success deleted!");
        }