示例#1
0
        /// <summary>
        /// 删除部门根据主键
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public bool DeleteDepartmentByDepartmentId(int departmentId)
        {
            bool       result  = true;
            RoleOp     roleOp  = new RoleOp();
            List <int> roleIds = roleOp.GetRolesForDepartmentAndSubDepartment(departmentId);

            if (roleIds != null && roleIds.Count > 0)
            {
                foreach (int id in roleIds)
                {
                    // 删除角色
                    result = result && roleOp.DeleteRoleByRoleId(id);
                }
            }

            //当前和所有子层级的部门id
            List <int> departmentIds = GetDpartmentIsForCurrentAndAllNodes(departmentId, true);

            if (departmentIds != null && departmentIds.Count > 0)
            {
                DepartmentManager     DepartmentManager     = new DepartmentManager();
                UserDepartmentManager userDepartmentManager = new UserDepartmentManager();
                foreach (int id in departmentIds)
                {
                    ///删除部门中的用户
                    result = result && userDepartmentManager.Delete(d => d.DepartmentId == departmentId);
                    ///删除部门
                    result = result && DepartmentManager.DeleteById(departmentId);
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// 部门批量移除人员
        /// </summary>
        /// <param name="departmentId"></param>
        /// <param name="userIds"></param>
        /// <param name="addUser"></param>
        /// <returns></returns>
        public bool DeleteUserForDepartment(int departmentId, List <int> userIds)
        {
            bool result = false;
            UserDepartmentManager userDepartmentManager = new UserDepartmentManager();

            //包含自己和所有下级(包括孙子节点。。。。)的部门id
            List <int> departmentsIncludeAllSub = GetDpartmentIsForCurrentAndAllNodes(departmentId, true);

            //删除关系 包括所有下级部门中的该用户
            if (userIds != null && userIds.Count > 0)
            {
                result = userDepartmentManager.Delete(d => userIds.Contains(d.UserId) && departmentsIncludeAllSub.Contains(d.DepartmentId));
            }

            ///删除部门中角色和人的关系
            RoleOp     roleOp  = new RoleOp();
            List <int> roleIds = roleOp.GetRolesForDepartmentAndSubDepartment(departmentId);

            if (userIds != null && userIds.Count > 0)
            {
                foreach (int id in userIds)
                {
                    roleOp.DeleteUserByRoleIds(roleIds, id);
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// 从所有部门中移除人
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteUserForDepartment(int userId)
        {
            UserDepartmentManager userDepartmentManager = new UserDepartmentManager();

            return(userDepartmentManager.Delete(d => d.UserId == userId));
        }