private void FillOrgGroupMembers(int OrgGroupID) { try { lbxOrgGroupMembers.Items.Clear(); DataSet ds = OrgGroupMembership.OrgGroupMembershipItems(OrgGroupID); DataView dv = new DataView(ds.Tables[0]); foreach (DataRowView drv in dv) { drv["DistinguishedName"] = drv["DistinguishedName"].ToString().Replace(",OU=", ","); drv["DistinguishedName"] = drv["DistinguishedName"].ToString().Replace("OU=", ""); } dv.Sort = "DistinguishedName"; lbxOrgGroupMembers.DataSource = dv; lbxOrgGroupMembers.DataTextField = "DistinguishedName"; lbxOrgGroupMembers.DataValueField = "ID"; lbxOrgGroupMembers.DataBind(); btnRemoveFromOrgGroup.Enabled = lbxOrgGroupMembers.Items.Count > 0 ? true : false; } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } }
protected void btnRemoveFromOrgGroup_Click(object sender, EventArgs e) { try { if (IsManager) { foreach (ListItem li in lbxOrgGroupMembers.Items) { if (li.Selected) { OrgGroupMembership membership = new OrgGroupMembership(int.Parse(li.Value)); if (!membership.Delete()) { Transaction xAction = new Transaction(); xAction.Action = string.Format("Failed to remove mapped OU {0} from OG {1}", li.Text, lbxOrgGroups.SelectedItem.Text); xAction.Category = "Application Administration"; xAction.Type = Transaction.TYPE_FAILURE; xAction.CreatedBy = CurrentUser.DisplayName; xAction.Insert(); } else { Transaction xAction = new Transaction(); xAction.Action = string.Format("Successfully removed mapped OU {0} from OG {1}", li.Text, lbxOrgGroups.SelectedItem.Text); xAction.Category = "Application Administration"; xAction.Type = Transaction.TYPE_SUCCESS; xAction.CreatedBy = CurrentUser.DisplayName; xAction.Insert(); } } } FillOrgGroupMembers(Int32.Parse(lbxOrgGroups.SelectedValue)); } else { ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('You do not have permissions to manage memberships!');", true); } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } }
protected void btnAddToOrgGroup_Click(object sender, EventArgs e) { try { if (IsManager) { foreach (ListItem li in lbxOrgUnits.Items) { if (li.Selected) { bool hasMapping = false; if (OrgUnit.Mapped(int.Parse(li.Value))) { hasMapping = true; OrgGroupMembership removeMember = new OrgGroupMembership(int.Parse(li.Value), true); if (removeMember.Delete()) { hasMapping = false; } } if (!hasMapping) { OrgGroupMembership member = new OrgGroupMembership(); member.OrgGroupID = int.Parse(lbxOrgGroups.SelectedValue); member.OrgUnitID = int.Parse(li.Value); member.CreatedBy = CurrentUser.DisplayName; member.ModifiedBy = CurrentUser.DisplayName; if (member.Insert()) { Transaction xAction = new Transaction(); xAction.Action = string.Format("Successfully mapped OU {0} to OG {1}", li.Text, lbxOrgGroups.SelectedItem.Text); xAction.Category = "Application Administration"; xAction.Type = Transaction.TYPE_SUCCESS; xAction.CreatedBy = CurrentUser.UserName; xAction.Insert(); } else { Transaction xAction = new Transaction(); xAction.Action = string.Format("Failed to map OU {0} to OG {1}", li.Text, lbxOrgGroups.SelectedItem.Text); xAction.Category = "Application Administration"; xAction.Type = Transaction.TYPE_FAILURE; xAction.CreatedBy = CurrentUser.UserName; xAction.Insert(); } } else { ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Previous mapping was not removed!');", true); } } } FillOrgGroupMembers(Int32.Parse(lbxOrgGroups.SelectedValue)); SetListItemColors(); } else { ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('You do not have permissions to manage memberships!');", true); } } catch (Exception ex) { SPA.Error.WriteError(ex); if (ShowDebug) { lblErrorMessage.Text = ex.ToString(); } } }