/// <summary> /// Creates a new security user profile entity instance from a membership user and adds it to the datastore. /// </summary> /// <param name="context">The datastore entity context to use.</param> /// <param name="user">The membership user to convert and add.</param> /// <returns>A <see cref="SecurityUserProfile"/> instance representing the newly created profile that has been added to the datastore.</returns> public static SecurityUserProfile AddToSecurityUserProfiles(this CPSecurityEntities context, MembershipUser user) { if (user == null) { return(null); } string username = user.UserName; string caid = UserManagement.GetCaid(username); SecurityUserProfile profile = context.AddToSecurityUserProfiles(username, UserManagement.GetCfisId(username), UserManagement.GetFullName(user), AccountAnalysis.ParseEntityType(caid), AccountAnalysis.ParseCommitteeID(caid), AccountAnalysis.ParseElectionCycle(caid), AccountAnalysis.ParseLiaisonID(caid), UserManagement.IsPasswordExpired(user)); return(profile); }
private void _listView_ItemActivate(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { ListViewItem item = this.SelectedItem; if (item == null) { return; } ActiveCandidate ac = null; if (_treeView.SelectedNode != null) { ac = _treeView.SelectedNode.Tag as ActiveCandidate; } var user = this.SelectedUser; if (user != null || item.Text.EndsWith("*")) { var status = this.SelectedIneligibilityStatus; if (status != null) { // other cycle user, prompt for open or update user = status.MatchedUser; if (user != null) { if (MessageBox.Show(this, string.Format("{0} already has an account from EC{1}. Would you like to associate this account with the EC{2} data before opening it?", user.DisplayName, user.SourceElectionCycle, ac.ElectionCycle), "Update Account?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { // remap account Entity entity = status.Entity; string contactID = status.ContactID; if (entity != null && contactID != null) { char?sourceCommitteeID = AccountAnalysis.ParseCommitteeID(contactID); byte?sourceLiaisonID = AccountAnalysis.ParseLiaisonID(contactID); if (sourceCommitteeID.HasValue) { user.SourceCommitteeID = sourceCommitteeID; } if (sourceLiaisonID.HasValue) { user.SourceLiaisonID = sourceLiaisonID; } if (ac != null) { user.SourceElectionCycle = ac.ElectionCycle; } user.SourceType = entity.Type; user.ElectionCycles.Add(ac.ElectionCycle); } if (!user.Save()) { MessageBox.Show(this, string.Format("An error occurred attempting to update {0}'s account. Please try again, or contact an administrator for further assistance.", user.DisplayName), "Account Update Failed", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } _refreshToolStripButton.PerformClick(); } } } if (user != null) { // show existing user account properties UserAccountForm.ShowExistingAccountForm(user, this.MdiParent); } } else { // create new user if (ac != null) { Entity entity = this.SelectedEntity; if (entity != null) { UserAccountForm.CreateNewAccountForm(entity, ac.ID, ac.ElectionCycle, item.Name).ShowAsOwnedBy(this.MdiParent); _refreshToolStripButton.PerformClick(); } else { var status = this.SelectedIneligibilityStatus; if (status != null) { entity = status.Entity; MessageBox.Show(this, string.Format("A C-Access user account cannot be created for {0} for the following reason:\n\n{1}", entity != null ? entity.Name : this.SelectedItem.Name, status.Status.GetDescription()), "Ineligible Contact", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { // does not match a leaf node, so expand tree lock (_listViewClickedLock) { _listViewClicked = true; } if (!_treeView.SelectedNode.IsExpanded) { _treeView.SelectedNode.Expand(); } var nodes = _treeView.SelectedNode.Nodes.Find(item.Name, false); if (nodes.Length > 0 && nodes[0].TreeView != null) { nodes[0].EnsureVisible(); _treeView.SelectedNode = nodes[0]; } } } } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// Creates a user account form for creating a new user account. /// </summary> /// <param name="entity">The entity to create a user account for.</param> /// <param name="candidateID">The ID of the candidate to associate with the new account.</param> /// <param name="electionCycle">The election cycle for which the new account is registered.</param> /// <param name="entityKey">The campaign-relative unique account analysis identifier for the entity.</param> /// <returns>A <see cref="UserAccountForm"/> purposed for creating a new user account for <paramref name="entity"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="entity"/> is null.</exception> public static UserAccountForm CreateNewAccountForm(Entity entity, string candidateID, string electionCycle, string entityKey) { UserAccountForm form = new UserAccountForm() { Text = CreateFormText }; form._mainTabControl.TabPages.Remove(form._generalTabPage); form._mainTabControl.TabPages.Remove(form._securityTabPage); form._mainTabControl.TabPages.Remove(form._electionsTabPage); form.IsCreateMode = true; form._initializing = true; form.SetCandidate(candidateID); form._initializing = false; // set CFIS entity context form.SetEntity(entity, AccountAnalysis.ParseEntityType(entityKey), candidateID, electionCycle, AccountAnalysis.ParseCommitteeID(entityKey), AccountAnalysis.ParseLiaisonID(entityKey)); return(form); }