コード例 #1
0
ファイル: DepartmentOp.cs プロジェクト: wang2650/Bap
        /// <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);
        }