コード例 #1
0
ファイル: PermissionController.cs プロジェクト: Iovezq/Puaa
        /// <summary>
        /// 角色管理页面
        /// </summary>
        /// <returns></returns>
        public ActionResult RoleManage()
        {
            //删除角色

            //接收角色id
            if (Request["num"] != null)
            {
                int id = Convert.ToInt32(Request["num"]);
                //根据角色id查询“员工角色表”此角色有无员工担当
                Employee_RoleInfo er = dal.GetEmployee_RoleInfoByRoleID(id);
                if (er != null)
                {
                    return(Content("0"));
                }
                else
                {
                    //根据角色id删除角色
                    bool isDel = dal.DelRoleByRoleID(id);
                    if (isDel)
                    {
                        return(Content("1"));
                    }
                }
            }


            //查询所有员工
            EmployeeDal         emdal  = new EmployeeDal();
            List <EmployeeInfo> emlist = emdal.GetAllEmployeer();
            //查询所有权限(查询菜单栏)
            PermissionDal         pd       = new PermissionDal();
            List <PermissionInfo> perslist = pd.GetAll();
            //查询所有角色
            List <RoleInfo> roles = dal.GetRoles();

            ViewBag.emlist = emlist;
            ViewBag.roles  = roles;


            int?   RoleID   = Convert.ToInt32(Request["RoleID"]);
            string RoleName = Request["RoleName"];

            if (RoleName != null)
            {
                Session["RoleName"] = RoleName;
            }
            if (RoleID != 0)
            {
                Session["RoleID"] = RoleID;
                List <RoleInfo_PermissionInfo> persByRoID   = dal.GetPerByRoleID(RoleID);
                List <PermissionInfo>          NotPerByRoId = dal.GetNotPerByRoId(RoleID);
                ViewBag.persByRoID   = persByRoID;
                ViewBag.NotPerByRoId = NotPerByRoId;
                ViewBag.perslist     = perslist;
            }


            return(View());
        }
コード例 #2
0
ファイル: EmployeeDal.cs プロジェクト: Iovezq/Puaa
        /// <summary>
        /// 通过用户id查询用户角色
        /// </summary>
        /// <param name="_roleid"></param>
        /// <returns></returns>
        public RoleInfo GetRoleByEmployeeID(int?_EmployeeId)
        {
            Employee_RoleInfo Em_role = t.Employee_RoleInfo.Where(a => a.EmployeeID == _EmployeeId).FirstOrDefault();
            RoleInfo          role    = new RoleInfo();

            if (Em_role != null)
            {
                role = t.RoleInfo.Where(a => a.ID == Em_role.RoleID).FirstOrDefault();
            }
            return(role);
        }
コード例 #3
0
ファイル: PermissionController.cs プロジェクト: Iovezq/Puaa
        /// <summary>
        /// 处理添加角色的方法
        /// </summary>
        /// <returns></returns>
        public ActionResult ExeAddEmployeerRole()
        {
            //获值
            //接收被授权员工的id
            int?emerid = Convert.ToInt32(Request["id"]);

            /*
             * 只能拥有一个角色
             */
            //接收角色id
            int?id = 0;

            if (Request["num"] != null)
            {
                id = Convert.ToInt32(Request["num"]);
            }

            //根据id查询角色
            Employee_RoleInfo haver = dal.GetRoleByID(id);

            if (haver != null)
            {
                //删除原本角色再添加新角色
                bool isDel = dal.DelEmpRole(haver);
                if (isDel)
                {
                    //添加角色
                    Employee_RoleInfo er = new Employee_RoleInfo();
                    er.EmployeeID = emerid;
                    er.RoleID     = id;
                    bool isAdd = dal.AddRoleByEmID(er);
                    if (isAdd)
                    {
                        return(RedirectToAction("PermissionManage"));
                    }
                }
            }
            else
            {
                //添加角色
                Employee_RoleInfo er = new Employee_RoleInfo();
                er.EmployeeID = emerid;
                er.RoleID     = id;
                bool isAdd = dal.AddRoleByEmID(er);
                if (isAdd)
                {
                    return(RedirectToAction("PermissionManage"));
                }
            }


            return(RedirectToAction("PermissionManage"));
        }
コード例 #4
0
ファイル: PermissionController.cs プロジェクト: Iovezq/Puaa
        /// <summary>
        /// 根据员工Id查询角色Id
        /// </summary>
        /// <returns>返回查询到的角色ID</returns>
        ///
        public void GetPerId()
        {
            //获取员工Id
            //接收被授权员工的id

            int?emerid = Convert.ToInt32(Request["Id"]);

            //实例员工角色对象

            PermissionDal dal = new PermissionDal();

            //获取对象
            Employee_RoleInfo emr = dal.GetRoleByID(emerid);

            //获取角色Id
            int?RoleID = Convert.ToInt32(emr.RoleID);


            //返回查询到的角色id
            Response.Write(RoleID);
            Response.End();
        }
コード例 #5
0
 /// <summary>
 /// 添加员工角色
 /// </summary>
 /// <param name="_er"></param>
 /// <returns></returns>
 public bool AddRoleByEmID(Employee_RoleInfo _er)
 {
     t.Employee_RoleInfo.Add(_er);
     return(t.SaveChanges() > 0);
 }
コード例 #6
0
 /// <summary>
 /// 删除员工角色
 /// </summary>
 /// <param name="_id"></param>
 /// <returns></returns>
 public bool DelEmpRole(Employee_RoleInfo _er)
 {
     t.Employee_RoleInfo.Remove(_er);
     return(t.SaveChanges() > 0);
 }