Пример #1
0
        /// <summary>
        /// Retrieves the details of a contact for a user account request.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="CommandEventArgs"/> that contains the event data.</param>
        protected void FetchContactCommand(object sender, CommandEventArgs e)
        {
            // retrieve treasurer or liaison/consultant contact details for display in create panel
            AnalysisResults results = CPProfile.AnalysisResults;
            Entity          contact;
            string          selection = _contactsList.SelectedValue;

            _contactSelection.Visible = false;
            if (_contactDetails.Visible = results.EligibleContacts.TryGetValue(selection, out contact))
            {
                _firstName.Text = contact.FirstName;
                _mi.Text        = contact.MiddleInitial.HasValue ? contact.MiddleInitial.Value.ToString() : null;
                _lastName.Text  = contact.LastName;
                _email.Text     = contact.Email;
                switch (AccountAnalysis.ParseEntityType(selection))
                {
                case EntityType.Liaison: _submitRequest.CommandName = LiaisonCommandName; break;

                case EntityType.Treasurer: _submitRequest.CommandName = TreasurerCommandName; break;

                case EntityType.Consultant: _submitRequest.CommandName = ConsultantCommandName; break;

                case EntityType.Candidate: _submitRequest.CommandName = CandidateCommandName; break;
                }
            }
            else
            {
                //_errorPanel.Visible = true;
            }
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
 public void Edit_Click()
 {
     if ((selectedAccountAnalysis == null) || (selectedAccountAnalysis.ACCOUNT_ANALYSIS_ID == 0))
     {
         MessageBox.Show("Please select a row to edit");
     }
     else
     {
         AccountAnalysis _AA = new AccountAnalysis();
         AddButtonVisibility  = Visibility.Hidden;
         EditButtonVisibility = Visibility.Visible;
         GROUP_BOX_TITLE      = "Edit Account Analysis";
         _AA.DataContext      = this;
         _AA.ShowDialog();
     }
 }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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));
                }
            }
        }
Пример #7
0
        /// <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();
        }
Пример #8
0
        /// <summary>
        /// Targets account viewer controls toward a specific user account.
        /// </summary>
        /// <param name="user">The <see cref="MembershipUser"/> account to use.</param>
        public new void SetUser(MembershipUser user)
        {
            // check for null user
            if (object.Equals(user, null))
            {
                return;
            }
            // check for known user
            if (object.Equals(Membership.GetUser(user.ProviderUserKey), null))
            {
                return;
            }
            base.SetUser(user);
            if (_candidate != null)
            {
                _candidateName.Text = string.Format("{0} (ID: {1})", _candidate.Name, _candidate.ID);
            }
            _username.Text    = user.UserName;
            _displayName.Text = UserManagement.GetFullName(user);
            _email.Text       = user.Email;
            GetActiveStatus(user);
            GetLockoutStatus(user);
            _onlineStatus.Checked              = user.IsOnline;
            _lastActivity.Text                 = user.LastActivityDate.Equals(user.CreationDate) ? Properties.Resources.NeverActiveText : user.LastActivityDate.ToString();
            _lastLockedOut.Text                = user.LastLockoutDate < user.CreationDate ? Properties.Resources.NeverLockedOutText : user.LastLockoutDate.ToString();
            _lastLoggedIn.Text                 = user.LastLoginDate.Equals(user.CreationDate) ? Properties.Resources.NeverLoggedInText : user.LastLoginDate.ToString();
            _lastPasswordChange.Text           = user.LastPasswordChangedDate.Equals(user.CreationDate) ? Properties.Resources.NeverChangedPasswordText : user.LastPasswordChangedDate.ToString();
            _newComment.Text                   = user.Comment;
            _comment.Text                      = Page.Server.HtmlEncode(user.Comment).Replace("\n", "<br />");
            _resetPasswordButton.OnClientClick = string.Format("return confirmReset('{0}','{1}');", user.UserName, user.Email);
            string caid = UserManagement.GetCaid(user.UserName);

            _contactType.Text          = AccountAnalysis.ParseEntityType(caid).ToString();
            _caid.Value                = caid;
            _synchronizeButton.Enabled = !string.IsNullOrEmpty(caid);
        }
Пример #9
0
 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;
     }
 }
Пример #10
0
        /// <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()
            });
        }
Пример #11
0
        public void Add_Click()
        {
            AccountAnalysis AccountAnalysisView = new AccountAnalysis();

            AccountAnalysisView.Show();
        }
Пример #12
0
        public void OpenAccountAnalysis_Click()
        {
            AccountAnalysis _AA = new AccountAnalysis();

            _AA.ShowDialog();
        }