private void AddUserPermission(object sender)
        {
            PermissionAssignmentType permissionType = (PermissionAssignmentType)((ToolStripMenuItem)sender).Tag;
            PermissionView           p = (PermissionView)((KeyValuePair <string, PermissionView>)userPermissionTree.SelectedNode.Tag).Value;

            userPermissionTree.BeginUpdate();
            bool allow;

            if (permissionType == PermissionAssignmentType.AllowFromUser)
            {
                allow = true;
            }
            else
            {
                allow = false;
            }
            BubbleDownUserPermission(p, allow, PermissionFrom.User);

            userPermissionTree.EndUpdate();
            userPermissionTree.Refresh();
            if (_selectedAccount != null && _selectedUser != null)
            {
                if (!_selectedUser.AssignedPermissions.ContainsKey(_selectedAccount.ID.Value))
                {
                    _selectedUser.AssignedPermissions.Add(_selectedAccount.ID.Value, new List <AssignedPermission>());
                }

                AssignedPermission current = null;

                foreach (var assignedPermission in _selectedUser.AssignedPermissions[_selectedAccount.ID.Value])
                {
                    if (assignedPermission.PermissionType == p.Path)
                    {
                        current = assignedPermission;
                        break;
                    }
                }
                if (current == null)
                {
                    current = new AssignedPermission()
                    {
                        PermissionName = p.Name, PermissionType = p.Path, Value = allow
                    };
                    _selectedUser.AssignedPermissions[_selectedAccount.ID.Value].Add(current);
                }
                else
                {
                    current.Value = allow;
                }
            }
        }
 private void BubbleDownGroupPermission(PermissionView permissionView, bool value, PermissionFrom from)
 {
     if (from == PermissionFrom.Group || from == PermissionFrom.Bubble)
     {
         if (value)
         {
             permissionView.PermissionAssignmentType = PermissionAssignmentType.AllowFromGroup;
         }
         else
         {
             permissionView.PermissionAssignmentType = PermissionAssignmentType.NotAllowFromGroup;
         }
     }
     else if (from == PermissionFrom.User)
     {
         if (value)
         {
             permissionView.PermissionAssignmentType = PermissionAssignmentType.AllowFromUser;
         }
         else
         {
             permissionView.PermissionAssignmentType = PermissionAssignmentType.NotAllowFromUser;
         }
     }
     if (permissionView != null)
     {
         foreach (var child in permissionView.ChildPermissions)
         {
             BubbleDownGroupPermission(child, value, PermissionFrom.Bubble);
         }
     }
     else             //isacount admin
     {
         foreach (var permission in _groupPermissions)
         {
             permission.Value.PermissionAssignmentType = PermissionAssignmentType.AllowFromGroup;
             foreach (var child in permission.Value.ChildPermissions)
             {
                 BubbleDownGroupPermission(child, true, PermissionFrom.Bubble);
             }
         }
     }
 }