/// <summary> /// Save user data /// </summary> /// <returns> /// The user id /// </returns> public Guid SaveUserData() { var returnId = Guid.Empty; if (this.PasswordField.Text.Length > 0 || this.ConfirmPasswordField.Text.Length > 0) { if (this.PasswordField.Text != this.ConfirmPasswordField.Text) { this.ComparePasswords.IsValid = false; } } // Only attempt a login if all form fields on the page are valid if (this.Page.IsValid) { var accountSystem = new UsersDB(); var countryId = string.Empty; if (this.CountryField.SelectedItem != null) { countryId = this.CountryField.SelectedItem.Value; } var stateId = 0; if (this.StateField.SelectedItem != null) { stateId = Convert.ToInt32(this.StateField.SelectedItem.Value); } try { if (this.UserName == string.Empty) { // Add New User to Portal User Database returnId = accountSystem.AddUser( this.NameField.Text, this.CompanyField.Text, this.AddressField.Text, this.CityField.Text, this.ZipField.Text, countryId, stateId, this.PhoneField.Text, this.FaxField.Text, this.PasswordField.Text, this.EmailField.Text, this.SendNewsletter.Checked, CurrentPortalSettings.PortalAlias); } else { // Update user if (this.PasswordField.Text.Equals(this.ConfirmPasswordField.Text) && this.PasswordField.Text.Equals(string.Empty)) { accountSystem.UpdateUser( this.OriginalUserId, this.NameField.Text, this.CompanyField.Text, this.AddressField.Text, this.CityField.Text, this.ZipField.Text, countryId, stateId, this.PhoneField.Text, this.FaxField.Text, this.EmailField.Text, this.SendNewsletter.Checked); } else { accountSystem.UpdateUser( this.OriginalUserId, this.NameField.Text, this.CompanyField.Text, this.AddressField.Text, this.CityField.Text, this.ZipField.Text, countryId, stateId, this.PhoneField.Text, this.FaxField.Text, this.PasswordField.Text, this.EmailField.Text, this.SendNewsletter.Checked, this.PortalSettings.PortalAlias); } // If we are here no error occurred } } catch (Exception ex) { this.Message.Text = General.GetString("REGISTRATION_FAILED", "Registration failed", this.Message) + " - "; if (ex is SqlException) { if (((SqlException)ex).Number == 2627) { this.Message.Text = General.GetString( "REGISTRATION_FAILED_EXISTING_EMAIL_ADDRESS", "Registration has failed. This email address has already been registered. Please use a different email address or use the 'Send Password' button on the login page.", this.Message); } } ErrorHandler.Publish(LogLevel.Error, "Error registering user", ex); } } return returnId; }