Beispiel #1
0
 /// <summary>
 /// Saves changes to the user.
 /// </summary>
 private void SaveUser()
 {
     if (!_user.Save())
     {
         MessageBox.Show(this, "An error occurred while saving your changes. Please try again.", "Save Unsuccessful", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
     }
     _user.Refresh();
     SetUser(_user);
 }
Beispiel #2
0
        private void _okButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            if (this.IsCreateMode)
            {
                // validate
                if (this.ValidateForm())
                {
                    // create new C-Access user account
                    char?  middleInitial = string.IsNullOrWhiteSpace(_miTextBox.Text) ? null : (char?)_miTextBox.Text.Trim().ToCharArray()[0];
                    string first         = _firstNameTextBox.Text.Trim();
                    string last          = _lastNameTextBox.Text.Trim();
                    CPUser user          = CPSecurity.Provider.CreateUser(first, middleInitial, last, _candidateID, _passwordTextBox.Text.Trim(), _cfisEmailTextBox.Text.Trim(), SettingsManager.CurrentUser.Username, _entityType, _committeeID, _electionCycle, _liaisonID, _newUsernameTextBox.Visible ? _newUsernameTextBox.Text : null);
                    if (user == null)
                    {
                        if (MessageBox.Show(this, string.Format("Unable to create a C-Access account for {0}. Retry?", Entity.ToFullName(first, last, middleInitial, false)), "Account Creation Failure", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
                        {
                            _okButton_Click(sender, e);
                        }
                    }
                    else
                    {
                        // auto-set security group
                        var groups = from g in CPSecurity.Provider.GetGroups()
                                     where g.Name == user.SourceType.ToString() + "s"
                                     select g.ID;
                        if (groups.Any())
                        {
                            CPSecurity.Provider.AddUserToGroups(user.UserName, groups.ToList());
                        }

                        // auto-set election cycle access
                        if (!user.IsCandidate && !string.IsNullOrWhiteSpace(_electionCycle))
                        {
                            user.ElectionCycles.Clear();
                            user.ImplicitElectionCycles = false;
                            user.ElectionCycles.Add(_electionCycle);
                            user.Save();
                        }
                        else
                        {
                            user.Refresh();
                        }

                        // refresh form
                        this.SetUser(user);
                        _mainTabControl.SelectedTab = _generalTabPage;
                        _cancelButton.Location      = _cancelButtonLocation;
                        RefreshAccountExplorers();
                    }
                }
            }
            else if (_applyButton.Enabled)
            {
                _applyButton.PerformClick();
                if (!_applyButton.Enabled)
                {
                    this.Close();
                }
            }
            else
            {
                this.Close();
            }
            this.Cursor = Cursors.Default;
        }