Beispiel #1
0
        private void btnEditSave_Click(object sender, RoutedEventArgs e)
        {
            if (((string)btnEditSave.Content) == "Edit")
            {
                setupEdit();
            }
            else // save
            {
                // are we saving an edited player, or a new one
                if (_addUser == false)
                {
                    if (!txtFirstName.Text.IsValidFirstName())
                    {
                        MessageBox.Show("Invalid First Name.");
                        txtFirstName.Focus();
                        txtFirstName.SelectAll();
                        return;
                    }
                    if (!txtLastName.Text.IsValidLastName())
                    {
                        MessageBox.Show("Invalid Last Name.");
                        txtLastName.Focus();
                        txtLastName.SelectAll();
                        return;
                    }
                    if (!txtEmail.Text.IsValidEmail())
                    {
                        MessageBox.Show("Bad email address.");
                        txtEmail.Focus();
                        txtEmail.SelectAll();
                        return;
                    }
                    if (!txtPhoneNumber.Text.IsValidPhoneNumber())
                    {
                        MessageBox.Show("Invalid Phone Number.");
                        txtPhoneNumber.Focus();
                        txtPhoneNumber.SelectAll();
                        return;
                    }

                    var newPlayer = new PlayerViewModel()
                    {
                        Email       = txtEmail.Text,
                        FirstName   = txtFirstName.Text,
                        LastName    = txtLastName.Text,
                        PhoneNumber = txtPhoneNumber.Text,
                        Active      = (bool)chkActive.IsChecked
                    };
                    List <string> roles = new List <string>();
                    foreach (var item in lstAssignedRoles.Items)
                    {
                        roles.Add((string)item);
                    }
                    newPlayer.Roles = roles;

                    try
                    {
                        _playerManager.EditPlayerProfile(_player, newPlayer,
                                                         _originalUnassignedRoles, _unassignedRoles);
                        this.DialogResult = true;
                    }
                    catch (Exception ex)
                    {
                        resetRoles();
                        if (ex.InnerException.Message.Contains("deactivated"))
                        {
                            chkActive.IsChecked = true;
                        }
                        MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message);
                    }
                }
                else // _addUser == true, so this needs to invoke an add method
                {
                    if (!txtFirstName.Text.IsValidFirstName())
                    {
                        MessageBox.Show("Invalid First Name.");
                        txtFirstName.Focus();
                        txtFirstName.SelectAll();
                        return;
                    }
                    if (!txtLastName.Text.IsValidLastName())
                    {
                        MessageBox.Show("Invalid Last Name.");
                        txtLastName.Focus();
                        txtLastName.SelectAll();
                        return;
                    }
                    if (!txtEmail.Text.IsValidEmail())
                    {
                        MessageBox.Show("Bad email address.");
                        txtEmail.Focus();
                        txtEmail.SelectAll();
                        return;
                    }
                    if (!txtPhoneNumber.Text.IsValidPhoneNumber())
                    {
                        MessageBox.Show("Invalid Phone Number.");
                        txtPhoneNumber.Focus();
                        txtPhoneNumber.SelectAll();
                        return;
                    }

                    var newPlayer = new PlayerViewModel()
                    {
                        //KonamiID = txtKonamiID.ToString().Text,
                        Email       = txtEmail.Text,
                        FirstName   = txtFirstName.Text,
                        LastName    = txtLastName.Text,
                        PhoneNumber = txtPhoneNumber.Text,
                        Active      = (bool)chkActive.IsChecked
                    };
                    List <string> roles = new List <string>();
                    foreach (var item in lstAssignedRoles.Items)
                    {
                        roles.Add((string)item);
                    }
                    newPlayer.Roles = roles;

                    try
                    {
                        _playerManager.AddNewPlayer(newPlayer);
                        this.DialogResult = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "\n\n" + ex.InnerException.Message);
                    }
                }
            }
        }