protected void Session_End(object sender, EventArgs e) { if (Session["Cart"] != null) { TP_Amazon_ClassLibrary.Cart cart = (TP_Amazon_ClassLibrary.Cart)Session["Cart"]; Serialize objSerialize = new Serialize(); objSerialize.WriteCartToDB(cart, Session["emailSession"]); } }
protected void btnLogin_Click(object sender, EventArgs e) { //1. check against database //2. grant access to next page based on successful login //GetAccountBy_CustomerEmail Stored Procedure to get the email stored in DB //Register object from the Register class in the "TP_Amazon_ClassLibrary" Register register = new Register(); Customer newCustomer = new Customer(); bool loginWorked; if (ddlLoginType.SelectedValue == "0") { loginWorked = register.ValidLogin(txtEmail.Text, txtPassword.Text); } else loginWorked = register.ValidMerchantLogin(txtEmail.Text, txtPassword.Text); //if session exists, load cookie value into txtbx if (Session["email"] !=null) { HttpCookie emailCookie = Request.Cookies["Login_Cookie"]; txtEmail.Text = emailCookie.Values["email"].ToString(); chkbxRemeberMe.Checked = true; } //if user enters a valid username and password if (loginWorked) { Serialize objSerialize = new Serialize(); TP_Amazon_ClassLibrary.Cart cart = (TP_Amazon_ClassLibrary.Cart)objSerialize.ReadCartFromDB(txtEmail.Text); if (cart != null) { Session["Cart"] = cart; } else { Session["Cart"] = new TP_Amazon_ClassLibrary.Cart(); } //store email in session then redirect Session["emailSession"] = txtEmail.Text; if (ddlLoginType.SelectedValue == "0") { Response.Redirect("ProductCatalog.aspx"); } else { Response.Redirect("AuntFreida.aspx"); } //if "Remember Me" is checked, store userName in cookie if (chkbxRemeberMe.Checked) { HttpCookie emailCookie = new HttpCookie("Login_Cookie");//cookie's name emailCookie.Values["email"] = txtEmail.Text; //set cookies value emailCookie.Values["LastVisited"] = DateTime.Now.ToString(); emailCookie.Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(emailCookie); } else { //remove user's email from username textbox Response.Cookies.Remove("mycookie"); } //gets or sets a new serialized cart object }//end of loginWorked if statement //else not a valid login else { lblLoginErrorMessage.Text = "Invalid Credentials. To create a new account select New User"; } }