Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
        public bool CreateRoleDepartment(ref List <string> result)
        {
            WXQ.BusinessCore.systemmanage.DepartmentOp departmentOp = new DepartmentOp(0);

            int  roleId       = 0;
            int  departmentId = 0;
            bool returnvalue  = true;
            ListResult <Enties.Department> departments = departmentOp.GetDepartmentList("", 0, 1, 10);

            if (departments.Result != null && departments.Result.Count > 0)
            {
                departmentId = departments.Result[0].DepartmentId;
            }
            WXQ.BusinessCore.systemmanage.UserOp userOp = new UserOp(0);
            PageModel pageModel = new PageModel
            {
                PageIndex = 1,
                PageSize  = 100
            };

            WXQ.BusinessCore.systemmanage.RoleOp roleOp = new RoleOp(0);
            List <Enties.Role> roles = roleOp.GetRoleList();

            if (roles != null && roles.Count > 0)
            {
                roleId = roles[0].RoleId;
            }

            #region 部门和用户关系

            DepartmentRoleManager departmentRoleManager = new DepartmentRoleManager();
            DepartmentRole        dr = new DepartmentRole
            {
                RoleId       = roleId,
                DepartmentId = departmentId
            };

            if (departmentRoleManager.Insert(dr))
            {
                result.Add("添加部门和角色关系成功");
            }
            else
            {
                result.Add("添加部门和角色关系失败");
            }

            #endregion 部门和用户关系

            return(returnvalue);
        }
Exemple #4
0
        /// <summary>
        /// 删除用户根据主键
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="isLogicalDelete">是否逻辑删除</param>
        /// <returns></returns>
        public bool DeleteUsersByUsersId(int userId, bool isLogicalDelete = false)
        {
            UsersManager UsersManager = new UsersManager();

            RoleOp roleOp = new RoleOp();

            // 删除人和角色关系
            roleOp.DeleteRoleRefByUserId(userId);


            DepartmentOp departmentOp = new DepartmentOp();

            //部门中移除该人
            departmentOp.DeleteUserForDepartment(userId);

            return(ReomveUserFormDb(userId, isLogicalDelete, UsersManager));
        }
Exemple #5
0
        /// <summary>
        /// 根据主键批量删除用户
        /// </summary>
        /// <param name="userIds">用户id</param>
        /// <param name="isLogicalDelete">是否逻辑删除</param>
        /// <returns></returns>
        public bool DeleteUsers(List <int> userIds, bool isLogicalDelete)
        {
            bool           result       = true;
            UsersManager   UsersManager = new UsersManager();
            RoleOp         roleOp       = new RoleOp();
            List <dynamic> ids          = new List <dynamic>();
            DepartmentOp   departmentOp = new DepartmentOp();

            foreach (int id in userIds)
            {
                // 删除人和角色关系
                result = result && roleOp.DeleteRoleRefByUserId(id);
                ///人和部门
                result = result && departmentOp.DeleteUserForDepartment(id);
                //删除自己
                result = result && ReomveUserFormDb(id, isLogicalDelete, UsersManager);
            }
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 创建关系
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool CreateRef(ref List <string> result)
        {
            bool returnvalue = true;
            int  userId      = 0;

            int roleId = 0;

            WXQ.BusinessCore.systemmanage.UserOp userOp = new UserOp(0);
            PageModel pageModel = new PageModel
            {
                PageIndex = 1,
                PageSize  = 100
            };
            ListResult <Enties.Users> users = userOp.GetUserList("", pageModel);

            if (users.Result != null && users.Result.Count > 0)
            {
                userId = users.Result[0].UsersId;
            }
            WXQ.BusinessCore.systemmanage.RoleOp roleOp = new RoleOp(0);
            List <Enties.Role> roles = roleOp.GetRoleList();

            if (roles != null && roles.Count > 0)
            {
                roleId = roles[0].RoleId;

                #region 角色和用户关系

                if (roleOp.AddUserForRole(roleId, userId))
                {
                    result.Add("添加角色和用户关系成功");
                }
                else
                {
                    result.Add("添加角色和用户关系失败");
                }

                #endregion 角色和用户关系
            }

            return(returnvalue);
        }
Exemple #7
0
        public bool CreateRoleMenu(ref List <string> result)
        {
            WXQ.BusinessCore.systemmanage.RoleOp roleOp = new RoleOp(0);
            List <Enties.Role> roles = roleOp.GetRoleList();
            int roleId = 0;

            if (roles != null && roles.Count > 0)
            {
                roleId = roles[0].RoleId;
            }

            PageModel pageModel = new PageModel
            {
                PageIndex = 1,
                PageSize  = 10000
            };

            #region 角色菜单关系

            WXQ.BusinessCore.systemmanage.MenuOp menuOp = new MenuOp(0);
            ListResult <Enties.Menu>             menus  = menuOp.GetMenuList("", "", -1, pageModel);
            if (menus != null && menus.Result.Count > 0)
            {
                List <int> menuids = menus.Result.Select(m => m.MenuId).ToList();

                if (menuOp.ModifyMentForRole(roleId, menuids))
                {
                    result.Add("添加角色菜单关系成功");
                }
                else
                {
                    result.Add("添加角色菜单关系失败");
                }
            }

            #endregion 角色菜单关系

            return(true);
        }
Exemple #8
0
        public bool CreateRole(ref List <string> result)
        {
            WXQ.BusinessCore.systemmanage.RoleOp op = new RoleOp(0);
            WXQ.Enties.Role role = new Enties.Role
            {
                RoleName    = "系统管理员",
                Description = "超级管理员角色"
            };
            bool returnvalue = true;

            if (op.InsertRole(role))
            {
                result.Add("添加角色成功");
            }
            else
            {
                returnvalue = false;
                result.Add("添加角色失败");
            }

            return(returnvalue);
        }