/// <summary> /// Handles contact selection by populating and showing an account creation form with the selected contact's information. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param> void SelectedContactChanged(object sender, EventArgs e) { // verify a selected contact string contactID = _contactsList.SelectedValue; if (string.IsNullOrEmpty(contactID)) { SetView(RenderContactSelection); } // verify a selected election cycle string ec = _electionCyclesList.Visible ? _electionCyclesList.SelectedValue : _electionCycle.Value; if (string.IsNullOrEmpty(ec)) { Cancel(this, new AccountManagementEventArgs()); } AnalysisResults aa = AccountAnalysis.Analyze(_candidate, ec); // get selected contact and populate form Entity contact; if (aa.EligibleContacts.TryGetValue(contactID, out contact)) { EntityType et = AccountAnalysis.ParseEntityType(contactID); _contactType.Text = et.ToString(); switch (et) { case EntityType.Candidate: case EntityType.Consultant: case EntityType.Liaison: case EntityType.Treasurer: break; default: _contactType.Text = "Unknown"; _actionButton.Enabled = false; break; } _firstName.Text = contact.FirstName; _middleInitial.Text = contact.MiddleInitial.ToString(); _lastName.Text = contact.LastName; _displayName.Text = contact.Name; _email.Text = contact.Email; _password.Text = Membership.GeneratePassword(10, 0); SetView(RenderCreateForm); } else { MessageText = string.Format("Error occurred retrieving selected contact (CAID: {0}). Please contact an Administrator for assistance.", contactID); } }
/// <summary> /// Populates a <see cref="DropDownList"/> with known contacts for a campaign for a specific election cycle. /// </summary> /// <param name="list">The <see cref="DropDownList"/> to populate.</param> /// <param name="electionCycle">The election cycle in which to search for contacts.</param> protected void FillEligibleContacts(DropDownList list, string electionCycle) { list.Items.Clear(); list.Items.Add(new ListItem("(no contacts available)", string.Empty)); if (_candidate == null) { return; } AnalysisResults results = AccountAnalysis.Analyze(_candidate, electionCycle); if (results.EligibleContacts.Count > 0) { list.Items.Clear(); list.Items.Add(new ListItem("(select a campaign contact)", string.Empty)); foreach (string id in results.EligibleContacts.Keys) { list.Items.Add(new ListItem(results.EligibleContacts[id].Name, id)); } } }
/// <summary> /// Populates a <see cref="DropDownList"/> with known contacts for a campaign for a specific election cycle, and also shows the status of other campaign contacts and accounts. /// </summary> /// <param name="list">The <see cref="DropDownList"/> to populate.</param> /// <param name="electionCycle">The election cycle in which to search for contacts.</param> new void FillEligibleContacts(DropDownList list, string electionCycle) { base.FillEligibleContacts(list, electionCycle); // populate current accounts if (_candidate == null) { return; } AnalysisResults aa = AccountAnalysis.Analyze(_candidate, electionCycle); _existingAccounts.Items.Clear(); foreach (CPUser user in aa.CurrentUsers) { _existingAccounts.Items.Add(string.Format("{0} ({1})", user.DisplayName, user.Email)); } _existingAccounts.Visible = _existingAccounts.Items.Count > 0; // populate ineligible contacts _ineligibleContacts.Visible = aa.IneligibleContacts.Count > 0; _ineligibleContacts.DataSource = aa.IneligibleContacts; _ineligibleContacts.DataBind(); }
/// <summary> /// Retrieves the content to display in a <see cref="ListView"/> when a <see cref="TreeNode"/> is selected. /// </summary> /// <param name="node">The <see cref="TreeNode"/> that was selected.</param> /// <returns>A <see cref="ListViewContents"/> that defines the columns and items of the content.</returns> private ListViewContents GetListItems(TreeNode node) { ColumnHeader[] headers = null; IEnumerable <ListViewItem> items = null; if (node.Tag is ActiveCandidate) { // active candidate leaf node selected, show active candidate contacts/users headers = new[] { _nameColumnHeader, _typeColumnHeader, _usernameColumnHeader, _emailColumnHeader }; ActiveCandidate ac = node.Tag as ActiveCandidate; AnalysisResults results = AccountAnalysis.Analyze(Cfb.CandidatePortal.Cfis.GetCandidate(ac.ID), ac.ElectionCycle); // users for current campaign var current = from u in results.CurrentUsers where _adminMode || u.SourceType != EntityType.Generic // hide generic accounts from non-admins select new ListViewItem(new[] { u.DisplayName, string.Format("User ({0})", u.SourceType), u.UserName, u.Email }, u.Enabled ? _userImageIndex : _userDisabledImageIndex) { Tag = u }; // existing users from a different campaign var other = from s in results.OtherCampaignUsers let u = s.MatchedUser select new ListViewItem(new[] { u.DisplayName + "*", string.Format("EC{0} User", u.SourceElectionCycle), u.UserName, u.Email }, u.Enabled ? _userImageIndex : _userDisabledImageIndex) { Tag = s }; // eligible contacts var eligible = from e in results.EligibleContacts let v = e.Value select new ListViewItem(new[] { v.Name, AccountAnalysis.ParseEntityType(e.Key).ToString(), null, v.Email }, _userInactiveImageIndex) { Name = e.Key, Tag = e.Value }; // ineligible contacts var ineligible = from s in results.IneligibleContacts select new ListViewItem(new[] { s.Entity.Name, "Ineligible Contact", null, s.Entity.Email }, _blockImageIndex) { Tag = s }; items = eligible.Union(ineligible).Union(current).Union(other); } else if (node.Tag as string == GroupNodeTag) { // group leaf node selected, show groups headers = new[] { _nameColumnHeader, _usernameColumnHeader, _idColumnHeader, _emailColumnHeader }; items = from u in CPSecurity.Provider.GetGroupMembers(node.Name) let user = CPSecurity.Provider.GetUser(u) where user != null && (_adminMode || user.SourceType != EntityType.Generic) select new ListViewItem(new[] { user.DisplayName, user.UserName, user.Cid, user.Email }, user.Enabled ? _userImageIndex : _userDisabledImageIndex) { Tag = user }; } else { // non-leaf nodes if (node == _candidatesNode) { headers = new[] { _nameColumnHeader, _typeColumnHeader, _idColumnHeader } } ; else if (node == _electionCyclesNode || node == _groupsNode || node.Tag is Candidate || node.ImageIndex == _electionCyclesImageIndex) { headers = new[] { _nameColumnHeader, _typeColumnHeader } } ; TreeNodeCollection children = node.Nodes; List <ListViewItem> treeNodeItems = new List <ListViewItem>(); foreach (TreeNode child in children) { ListViewItem item = null; if (child.ImageIndex == _candidatesImageIndex && child.Tag is Candidate) { Candidate cand = child.Tag as Candidate; item = new ListViewItem(new[] { cand.FormalName, "Candidate", cand.ID }, _candidatesImageIndex) { Name = cand.ID, Tag = child.Tag }; } else if (child.ImageIndex == _electionCyclesImageIndex) { item = new ListViewItem(new[] { child.Name, "Election Cycle" }, _electionCyclesImageIndex) { Name = child.Name, Tag = child.Tag }; } else if (node.ImageIndex == _groupsImageIndex) { item = new ListViewItem(new[] { child.Name, "Security Group" }, _groupsImageIndex) { Name = child.Name }; } if (item != null) { treeNodeItems.Add(item); } } items = treeNodeItems; } return(new ListViewContents() { Headers = headers, Items = items.OrderBy(i => i.Text).ToArray() }); }