protected void btnSubmitChanges_Click(object sender, EventArgs e)
{
// used for zip TryParse
int result = 0;
// check values of the textboxes, displaying the appropriate values, then
// commit changes to the DB
if (txtFirstName.Text == "" || txtFirstName.Text == "First Name")
{
ErrorText.Text = "First name required";
}
else if (txtLastName.Text == "" || txtLastName.Text == "Last Name")
{
ErrorText.Text = "Last name required";
}
else if (txtAddress.Text == "" || txtAddress.Text == "Address 1")
{
ErrorText.Text = "Address 1 required";
}
else if (txtCity.Text == "" || txtCity.Text == "City")
{
ErrorText.Text = "City name required";
}
else if (!int.TryParse(txtZip.Text, out result))
{
ErrorText.Text = "Invalid Zip";
}
else if (txtEmail.Text == "" || txtEmail.Text == "E-Mail")
{
ErrorText.Text = "E-Mail required";
}
else
{
// create customer data access object
CustomerDA customerDA = new CustomerDA();
// get references to the textboxes on the page
MembershipUser currentUser = Membership.GetUser();
try
{
// create a customer business object
Customer customerObj = new Customer(customerID, true, currentUser.UserName, txtFirstName.Text,
txtLastName.Text, txtAddress.Text, txtAddress2.Text, txtCity.Text, cboState.Text, txtZip.Text, cboCountry.Text);
// commit customer business object to the DB using the CustomerDA
customerDA.Save(customerObj);
// Update user e-mail
currentUser.Email = txtEmail.Text;
Membership.UpdateUser(currentUser);
}
catch (Exception ex)
{
// there was an error in updating the users account
Response.Redirect("~/404.aspx");
}
// redirect the user back to their profile
Response.Redirect("ViewProfile.aspx");
}
}