protected void btnSave_Click(object sender, EventArgs e) { MetaObject mo = Mediachase.Ibn.Data.Services.RoleManager.GetObjectRole(mc, RoleName); MetaObject moState = StateMachineUtil.GetObjectRoleStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (moState == null) { MetaClass stateClass = StateMachineUtil.GetObjectRoleStateMetaClass(ClassName); moState = new MetaObject(stateClass); } MetaObjectPropertyCollection properties = moState.Properties; properties[StateMachineUtil.RoleField].Value = mo.PrimaryKeyId.Value; properties[StateMachineUtil.StateMachineField].Value = StateMachineId; properties[StateMachineUtil.StateField].Value = StateId; for (int i = 0; i < rights.Count; i++) { string rightName = rights[i].ToString(); properties[rightName].Value = ((CheckControl)checkControls[i]).Value; } moState.Save(); // Closing window if (RefreshButton == String.Empty) { CHelper.CloseItAndRefresh(Response); } else // Dialog Mode { CHelper.CloseItAndRefresh(Response, RefreshButton); } }
private void BindData() { MetaObject mo = Mediachase.Ibn.Data.Services.RoleManager.GetObjectRole(mc, RoleName); MetaObject moState = StateMachineUtil.GetObjectRoleStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (mo != null) { txtName.Text = mo.Properties["RoleName"].Value.ToString(); } if (moState != null) { MetaObjectPropertyCollection properties = moState.Properties; for (int i = 0; i < states.Count; i++) { string stateName = states[i].ToString(); ((CheckControl)checkControls[i]).Value = (int)properties[stateName].Value; } } }
private void BindData() { MetaObject mo = Mediachase.Ibn.Data.Services.RoleManager.GetObjectRole(mc, RoleName); MetaObject moState = StateMachineUtil.GetObjectRoleStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (mo != null) { string roleName = mo.Properties["RoleName"].Value.ToString(); RoleNameLabel.Text = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString()); if (mo.Properties["ClassName"].Value != null) { string className = (string)mo.Properties["ClassName"].Value; if (className.Contains("::")) { string[] s = new string[] { "::" }; className = className.Split(s, StringSplitOptions.None)[0]; RoleNameLabel.Text = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", RoleNameLabel.Text, CHelper.GetResFileString(MetaDataWrapper.GetMetaClassByName(className).PluralName)); } } } if (moState == null) { moState = mo; } MetaObjectPropertyCollection properties = moState.Properties; if (moState != null) { for (int i = 0; i < rights.Count; i++) { string rightName = rights[i].ToString(); ((CheckControl)checkControls[i]).Value = (int)properties[rightName].Value; } } }
private void BindGrid() { if (sm == null) { sm = new Mediachase.Ibn.Data.Services.StateMachine(mc, int.Parse(ddlStateMachine.SelectedValue)); } // DataTable structure DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add(roleColumn, typeof(string)); MetaObject moState = StateMachineManager.GetState(mc, int.Parse(ddlState.SelectedValue)); string fromState = moState.Properties["Name"].Value.ToString(); foreach (State state in sm.States) { StateTransition st = sm.FindTransition(fromState, state.Name); if (st != null) { dt.Columns.Add(state.Name, typeof(string)); } } dt.Columns.Add(editColumn, typeof(string)); // Fill data DataRow dr; foreach (MetaObject mo in Mediachase.Ibn.Data.Services.RoleManager.GetObjectRoleItems(mc.Name)) { string roleName = mo.Properties["RoleName"].Value.ToString(); dr = dt.NewRow(); dr[roleColumn] = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString()); if (mo.Properties["ClassName"].Value != null) { string className = (string)mo.Properties["ClassName"].Value; if (className.Contains("::")) { string[] s = new string[] { "::" }; className = className.Split(s, StringSplitOptions.None)[0]; } dr[roleColumn] += String.Format(" ({0})", CHelper.GetResFileString(MetaDataWrapper.GetMetaClassByName(className).PluralName)); } MetaObject obj = StateMachineUtil.GetObjectRoleStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(ddlStateMachine.SelectedValue), int.Parse(ddlState.SelectedValue)); for (int i = 1; i < grdMain.Columns.Count - 1; i++) { BoundField rightsField = grdMain.Columns[i] as BoundField; if (rightsField != null) { string fieldName = rightsField.DataField; if (obj != null) { dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value); } else { dr[fieldName] = CHelper.GetPermissionImage((int)Mediachase.Ibn.Data.Services.Security.Rights.None); } } } string url = String.Format("javascript:ShowWizard("{7}?ClassName={0}&btn={1}&Role={2}&SmId={3}&StateId={4}", {5}, {6});", mc.Name, Page.ClientScript.GetPostBackEventReference(lnkRefresh, ""), roleName, ddlStateMachine.SelectedValue, ddlState.SelectedValue, dialogWidth, dialogHeight, ResolveClientUrl("~/Apps/Security/Pages/Admin/ObjectRoleStateTransitionEdit.aspx")); dr[editColumn] = String.Format("<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString()); dt.Rows.Add(dr); } grdMain.DataSource = dt; grdMain.DataBind(); }
private void BindGrid() { // DataTable structure DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add(idColumn, typeof(string)); dt.Columns.Add(roleColumn, typeof(string)); dt.Columns.Add(isInheritedColumn, typeof(bool)); CustomTableRow[] classRights = CustomTableRow.List(SqlContext.Current.Database.Tables[Mediachase.Ibn.Data.Services.Security.BaseRightsTableName], FilterElement.EqualElement("ClassOnly", 1)); foreach (SecurityRight right in Mediachase.Ibn.Data.Services.Security.GetMetaClassRights(mc.Name)) { // Check for Class Right (ex. Create) bool isClassRight = false; string rightUid = right.BaseRightUid.ToString(); foreach (CustomTableRow r in classRights) { if (r["BaseRightUid"].ToString() == rightUid) { isClassRight = true; break; } } if (isClassRight) { continue; } dt.Columns.Add(right.RightName, typeof(string)); } dt.Columns.Add(editColumn, typeof(string)); dt.Columns.Add(resetColumn, typeof(string)); // Fill data DataRow dr; foreach (MetaObject mo in Mediachase.Ibn.Data.Services.RoleManager.GetObjectRoleItems(mc.Name)) { string roleName = mo.Properties["RoleName"].Value.ToString(); dr = dt.NewRow(); dr[idColumn] = mo.PrimaryKeyId; dr[roleColumn] = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString()); if (mo.Properties["ClassName"].Value != null) { string className = (string)mo.Properties["ClassName"].Value; if (className.Contains("::")) { string[] s = new string[] { "::" }; className = className.Split(s, StringSplitOptions.None)[0]; } dr[roleColumn] += String.Format(CultureInfo.InvariantCulture, " ({0})", CHelper.GetResFileString(MetaDataWrapper.GetMetaClassByName(className).PluralName)); } bool isInhereted = false; MetaObject obj = StateMachineUtil.GetObjectRoleStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(StateMachineList.SelectedValue, CultureInfo.InvariantCulture), int.Parse(StateList.SelectedValue, CultureInfo.InvariantCulture)); if (obj == null) { obj = mo; isInhereted = true; } for (int i = 1; i < MainGrid.Columns.Count - 2; i++) { BoundField rightsField = MainGrid.Columns[i] as BoundField; if (rightsField != null) { string fieldName = rightsField.DataField; dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value, isInhereted); } } dr[isInheritedColumn] = isInhereted; string url = String.Format(CultureInfo.InvariantCulture, "javascript:ShowWizard("{7}?ClassName={0}&btn={1}&Role={2}&SmId={3}&StateId={4}", {5}, {6});", mc.Name, Page.ClientScript.GetPostBackEventReference(RefreshButton, ""), roleName, StateMachineList.SelectedValue, StateList.SelectedValue, dialogWidth, editDialogHeight, ResolveClientUrl("~/Apps/Security/Pages/Admin/ObjectRoleStateEdit.aspx")); dr[editColumn] = String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString()); dt.Rows.Add(dr); } MainGrid.DataSource = dt; MainGrid.DataBind(); }