Ejemplo n.º 1
0
        public List <ProcessTaskTree> GetProcessTree(int id)
        {
            Guid processGuid = _context.Processes.SingleOrDefault(c => c.Id == id).ProcessGuid;

            var processTasks = _context.ProcessTasks.Where(pt => pt.ProcessGuid == processGuid).ToList();

            bool allNodesAdded           = true;
            List <ProcessTaskTree> ptree = new List <ProcessTaskTree>();
            ProcessTaskTree        root  = new ProcessTaskTree();

            foreach (var pt in processTasks)
            {
                if (pt.TaskTypeId == 5)
                {
                    root.name = pt.TaskName;
                    root      = updateTree(root, pt.ProcessTaskGuid);
                }
            }

            ptree.Add(root);
            return(ptree);
        }
Ejemplo n.º 2
0
        ProcessTaskTree updateTree(ProcessTaskTree node, Guid nodeGuid)
        {
            var children = _context.ProcessTaskTransition.Where(ptt => ptt.SourceTaskGuid == nodeGuid).ToList();

            if (children.Count == 0)
            {
                return(node);
            }

            else
            {
                node.children = new List <ProcessTaskTree>();

                foreach (var child in children)
                {
                    ProcessTaskTree newNode = new ProcessTaskTree();

                    var destinationTask = _context.ProcessTasks
                                          .Where(cd => cd.ProcessTaskGuid == child.DestinationTaskGuid)
                                          .FirstOrDefault();

                    newNode.name = destinationTask.TaskName;

                    node.children.Add(newNode);

                    var destChildren = _context.ProcessTaskTransition.Where(ptt => ptt.SourceTaskGuid == destinationTask.ProcessTaskGuid)
                                       .ToList();
                    if (destChildren.Count > 0)
                    {
                        newNode = updateTree(newNode, destinationTask.ProcessTaskGuid);
                    }
                }

                return(node);
            }
        }