示例#1
0
    protected void btnAddResources_Click(object sender, EventArgs e)
    {
        try
        {
            if (ddlGroupName.SelectedIndex != 0)
            {
                //GetPermission(TireTraxLib.ResourceType.PagePermissions, ref canView, ref canAdd, ref canUpdate, ref canDelete,ddlGroupName.SelectedValue);
                //if (!canUpdate)
                //{
                //    lblInfo.Text = "Sorry, you dont have right to change the premission";
                //}
                //else
                //{
                int         groupId     = Convert.ToInt32(ddlGroupName.SelectedValue.ToString());
                AccessToken token       = new AccessToken();
                string      accessToken = AccessToken.ReturnEmptyToken();
                if (chkAdmin.Checked)
                {
                    accessToken = token.AdminToken(64, accessToken);
                }
                else
                {
                    accessToken = ReadPermissions(accessToken, token);
                }

                RoleManagement.UpdateSecurityToken(groupId, accessToken);

                //it is used to update the Security token for Roles
                DataTable dt = RoleManagement.getDistinctRolesByGroupId(groupId);
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        int TempRoleId    = Conversion.ParseInt(dt.Rows[i]["RoleId"]);
                        int TempSubRoleId = Conversion.ParseInt(dt.Rows[i]["SubRoleId"]);
                        regenerateSecurityTokens(TempRoleId, TempSubRoleId);
                    }
                }
                lblInfo.ForeColor = System.Drawing.Color.Green;
                lblInfo.Text      = "Permission is Successfully Added";

                //Update Cookies
                // UserInfo user = UserInfo.GetCurrentUserInfo();
                Response.Cookies["securityToken"].Expires = DateTime.Now.AddMinutes(-1);
                string securityToken = string.Empty;
                securityToken = RoleManagement.GetSecurityTokenByRoleId(groupId);
                //HttpCookie securityCookie = new HttpCookie("securityToken");
                //Decoder d= Encoding.UTF8.GetDecoder();

                //securityCookie.Value = Server.UrlEncode(securityToken);
                //HttpContext.Current.Response.Cookies.Add(securityCookie);
                // }
            }
            else
            {
                lblInfo.ForeColor = System.Drawing.Color.Red;
                lblInfo.Text      = "Please Select the Group";
            }
        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "PagePermission.aspx btnAddResources_Click", ex);
        }
    }