protected void uxAuthenticate_Click(object sender, EventArgs e) { var customer = CustomersManager.Authenticate(uxFirstname.Text, uxLastName.Text); if (customer == null) { uxMessage.Text = "Customer not present"; uxFirstname.Text = string.Empty; uxLastName.Text = string.Empty; uxFirstname.Focus(); return; } // Add customer ID to session Session.Add("CustomerID", customer.ID); // instatiate cookie and add customer ID to cookie HttpCookie cookieCustID = new HttpCookie("CustomerID"); cookieCustID.Value = Convert.ToString(customer.ID); cookieCustID.Expires = DateTime.Now.AddMonths(1); // cookie expires after 1 month Response.Cookies.Add(cookieCustID); FormsAuthentication.RedirectFromLoginPage(customer.FullName, false); }
protected void btnSubmit_Click(object sender, EventArgs e) { var db = new MarinaEntities(); var customer = CustomersManager.Authenticate(uxFirstName.Text, uxLastName.Text); if (customer == null) // if new customer, add the customer to the DB { Customer cust = new Customer { FirstName = uxFirstName.Text, LastName = uxLastName.Text, Phone = uxPhone.Text, City = uxCity.Text }; CustomersManager.Add(cust); // Response.Redirect("~/"); } //at this point, student is not null meaning we have a valid authentication //so add student id to session Session.Add("CustomerID", customer.ID); // redirect - false means no persistent cookie FormsAuthentication.RedirectFromLoginPage(customer.FullName, false); Response.Redirect("~/MyLease"); }