Example #1
0
 static void InsertUsers(List <IdName> returnValue, DepartmentTree node)
 {
     foreach (var user in DepartmentUsers)
     {
         if (node.Node.Id == user.DepartmentId)
         {
             bool found = false;
             foreach (var idName in returnValue)
             {
                 if (idName.Id == user.UserId)
                 {
                     found = true;
                 }
             }
             if (!found)
             {
                 returnValue.Add(new IdName {
                     Id = user.UserId, Name = UserBLL.GetNameById(user.UserId)
                 });
             }
         }
         foreach (var subNode in node.Children)
         {
             InsertUsers(returnValue, subNode);
         }
     }
 }
Example #2
0
        static public List <IdName> GetDepartmentUsersIdNames(int deptid)
        {
            List <IdName>  list = new List <IdName>();
            DepartmentTree node = FindNode(deptid, Root);

            if (node != null)
            {
                InsertUsers(list, node);
            }
            return(list);
        }
Example #3
0
 public static void UpdateDepartments()
 {
     Departments     = (from o in db.Departments.AsNoTracking() select o).ToList();
     DepartmentUsers = (from o in db.DepartmentUsers.AsNoTracking() select o).ToList();
     foreach (var department in Departments)
     {
         if (department.PId == 0)
         {
             Root = new DepartmentTree {
                 Node = department
             };
             AddChildren(Root);
             break;
         }
     }
 }
Example #4
0
 static DepartmentTree FindNode(int deptid, DepartmentTree parent)
 {
     if (parent.Node.Id == deptid)
     {
         return(parent);
     }
     foreach (var node in parent.Children)
     {
         var found = FindNode(deptid, node);
         if (found != null)
         {
             return(found);
         }
     }
     return(null);
 }
Example #5
0
 static void AddChildren(DepartmentTree node)
 {
     if (node.Children == null)
     {
         node.Children = new List <DepartmentTree>();
     }
     foreach (var department in Departments)
     {
         if (department.PId == node.Node.Id)
         {
             var child = new DepartmentTree {
                 Node = department
             };
             node.Children.Add(child);
             AddChildren(child);
         }
     }
 }