protected void btnSave_Click(object sender, EventArgs e) { Customer customer = customerRepo.GetById(ToSQL.SQLToInt(Request.QueryString["Id"])); if (customer != null) { lbMessage.Text = ""; if (customerRepo.DoesEmailExist(txtEmail.Text) && !customer.Email.ToLower().Equals(txtEmail.Text.ToLower()) && ToSQL.EmptyNull(txtEmail.Text) != "") { lbMessage.Text = "Email already exists!"; lbMessage.ForeColor = System.Drawing.Color.Red; txtEmail.Text = ""; return; } customer.FirstName = txtFirstName.Text; customer.LastName = txtLastName.Text; customer.Email = txtEmail.Text; customer.Phone = txtPhone.Text; customer.DateOfBirth = ToSQL.SQLToDateTimeNull(txtDateOfBirth.Text); customer.Gender = rdbtnGender.SelectedIndex == 0 ? true : false; int i = customerRepo.UpdateCustomer(customer); Response.Redirect("Management-Customer.aspx"); } else { Response.Redirect("Management-Customer.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { CustomerRepo customerrepo = new CustomerRepo(); lbMessage.Text = ""; if (customerrepo.DoesUsernameExist(txtUserName.Text)) { lbMessage.Text = "Username already exists!"; lbMessage.ForeColor = System.Drawing.Color.Red; txtUserName.Text = ""; return; } if (customerrepo.DoesEmailExist(txtEmail.Text)) { lbMessage.Text = "Email already exists!"; lbMessage.ForeColor = System.Drawing.Color.Red; txtEmail.Text = ""; return; } Model.Customer customer = new Model.Customer(); customer.FirstName = txtFirstName.Text; customer.LastName = txtLastName.Text; customer.Username = txtUserName.Text; customer.Password = Security.Encrypt(ConfigurationManager.AppSettings["KeyCustomer"], txtPassword.Text); customer.Key = ConfigurationManager.AppSettings["KeyCustomer"]; customer.Email = txtEmail.Text; customer.Phone = txtPhone.Text; customer.DateOfBirth = ToSQL.SQLToDateTimeNull(txtDateOfBirth.Text); customer.Gender = rdbtnGender.SelectedIndex == 0 ? true : false; customer.DateCreated = DateTime.Now; int i = customerrepo.CreateCustomer(customer); Response.Redirect("Management-Customer.aspx"); }