Ejemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    var roles = CustomerManager.GetAllCustomerRoles();
                    if (roles.Count == 0)
                    {
                        lblMessage.Text = GetLocaleResourceString("Admin.ACL.NoRolesDefined");
                        return;
                    }
                    SettingManager.SetParam("ACL.Enabled", cbACLEnabled.Checked.ToString());

                    foreach (GridViewRow row in gvACL.Rows)
                    {
                        foreach (CustomerRole cr in roles)
                        {
                            CheckBox    cbAllow            = row.FindControl(string.Format("cbAllow_{0}", cr.CustomerRoleId)) as CheckBox;
                            HiddenField hfCustomerActionId = row.FindControl(string.Format("hfCustomerActionId_{0}", cr.CustomerRoleId)) as HiddenField;
                            if (cbAllow == null || hfCustomerActionId == null || String.IsNullOrEmpty(hfCustomerActionId.Value))
                            {
                                return;
                            }

                            bool allow            = cbAllow.Checked;
                            int  customerActionId = int.Parse(hfCustomerActionId.Value);

                            var acls = ACLManager.GetAllAcl(customerActionId, cr.CustomerRoleId, null);
                            if (acls.Count > 0)
                            {
                                ACL acl = acls[0];
                                ACLManager.UpdateAcl(acl.AclId, customerActionId, cr.CustomerRoleId, allow);
                            }
                            else
                            {
                                ACL acl = ACLManager.InsertAcl(customerActionId, cr.CustomerRoleId, allow);
                            }
                        }
                    }

                    Response.Redirect("ACL.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }
Ejemplo n.º 2
0
        protected void BindGrid()
        {
            var actions = ACLManager.GetAllCustomerActions();

            if (actions.Count == 0)
            {
                lblMessage.Text = GetLocaleResourceString("Admin.ACL.NoActionDefined");
                return;
            }
            var roles = CustomerManager.GetAllCustomerRoles();

            if (roles.Count == 0)
            {
                lblMessage.Text = GetLocaleResourceString("Admin.ACL.NoRolesDefined");
                return;
            }
            List <CustomerActionACLMappingHelperClass> dt = new List <CustomerActionACLMappingHelperClass>();

            foreach (CustomerAction ca in actions)
            {
                CustomerActionACLMappingHelperClass map1 = new CustomerActionACLMappingHelperClass();
                map1.CustomerActionId   = ca.CustomerActionId;
                map1.CustomerActionName = ca.Name;
                map1.Allow = new Dictionary <int, bool>();

                foreach (CustomerRole cr in roles)
                {
                    var acls = ACLManager.GetAllAcl(ca.CustomerActionId, cr.CustomerRoleId, null);
                    if (acls.Count > 0)
                    {
                        ACL acl = acls[0];
                        map1.Allow.Add(cr.CustomerRoleId, acl.Allow);
                    }
                    else
                    {
                        map1.Allow.Add(cr.CustomerRoleId, false);
                    }
                }
                dt.Add(map1);
            }

            gvACL.DataSource = dt;
            gvACL.DataBind();
        }