예제 #1
0
        /// <summary>
        /// 添加角色权限的方法
        /// </summary>
        /// <returns></returns>
        public ActionResult ExeAddRolePers()
        {
            //接收权限ids
            string ids = Request["nums"];
            //接收被授权角色的id
            int?roleid = Convert.ToInt32(Request["id"]);

            //在添加角色权限时 先查询该角色权限 将该角色权限全部删除 再进行授权
            List <RoleInfo_PermissionInfo> li = dal.GetPerByRoleID(roleid);

            if (li.Count > 0)                            //有权限
            {
                bool isDel = dal.DelPerByRoleID(roleid); //删除权限
                if (isDel)
                {
                    //添加权限
                    List <string> list  = ids.Split(',').ToList();
                    bool          isAdd = false;
                    for (int i = 0; i < list.Count() - 1; i++)
                    {
                        RoleInfo_PermissionInfo rp = new RoleInfo_PermissionInfo();
                        rp.RoleId       = roleid;
                        rp.PermissionID = Convert.ToInt32(list[i]);
                        isAdd           = dal.AddPerByRoleID(rp);
                    }

                    if (isAdd)
                    {
                        return(Content("0"));
                    }
                }
            }
            else//没有权限
            {
                //添加权限
                List <string> list  = ids.Split(',').ToList();
                bool          isAdd = false;
                for (int i = 0; i < list.Count() - 1; i++)
                {
                    RoleInfo_PermissionInfo rp = new RoleInfo_PermissionInfo();
                    rp.RoleId       = roleid;
                    rp.PermissionID = Convert.ToInt32(list[i]);
                    isAdd           = dal.AddPerByRoleID(rp);
                }

                if (isAdd)
                {
                    return(Content("0"));
                }
            }
            return(RedirectToAction("PermissionManage"));
        }