protected void btnSubmit_Click(object sender, EventArgs e) { MarinaEntities1 db = new MarinaEntities1(); // create the DataAccess entity Customer newCust = new Customer(); // empty Customer object bool exists; // used for determining if user exists or not lblRegStatus.Text = ""; if (txtFName.Text != "" && txtLName.Text != "" && txtCity.Text != "" && txtPhone.Text != "" && txtEmail.Text != "" && txtPassword.Text != "") { try {// search the db for the email address newCust = (from c in db.Customers where c.EMail == txtEmail.Text select c).Single(); exists = true; // yes we have an existing user } catch (System.InvalidOperationException) { // error when no data exists exists = false; // no user found } if (!exists) // no user found, validate and create { newCust.FirstName = txtFName.Text; newCust.LastName = txtLName.Text; newCust.City = txtCity.Text; newCust.Phone = txtPhone.Text; newCust.EMail = txtEmail.Text; newCust.Salt = newCust.GetSalt(); newCust.Password = newCust.EncryptPassword(txtPassword.Text, newCust.Salt); db.Customers.Add(newCust); db.SaveChanges(); Session["Authenticated"] = true; Session["Username"] = txtEmail.Text; Response.Redirect("LeaseSlip.aspx"); } } else { lblRegStatus.Text = "All fields required"; } }
public void DoLease(int slipNum) { //int chosenSlip = Convert.ToInt32(txtChosen.Text); // get the customer's choice of slip to lease using (MarinaEntities1 db = new MarinaEntities1()) { // getting these again due to missing some crucial info in class while away -Tom List <int> leaseList = (from lease in db.Leases select lease.SlipID).ToList(); List <int> availList = (from slip in db.Slips select slip.ID).ToList(); // create a new lease with the customer and slip ID Lease leased = new Lease(); leased.CustomerID = cust.ID; leased.SlipID = slipNum; // save to the database db.Leases.Add(leased); db.SaveChanges(); GetLeases(username); lvAvailableSlips.SelectedIndex = -1; } }