protected void add_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("In add_Click"); UInt64 productID = Convert.ToUInt64(Server.UrlDecode(Request.QueryString ["productID"])); using (MySqlConnection database = new MySqlConnection(ConnectionStrings.DBConnectionString)) { database.Open(); using (MySqlCommand selectProduct = new MySqlCommand("Select * from products left join categories on products.categoryID = categories.categoryID where products.productID = @productID", database)) { selectProduct.Parameters.AddWithValue("@productID", productID); using (MySqlDataReader reader = selectProduct.ExecuteReader()) { reader.Read(); Classes.Cart cart = null; if (Session ["cart"] == null) { cart = new Classes.Cart(); Session ["cart"] = cart; System.Diagnostics.Debug.WriteLine("Created cart"); } else { cart = (Classes.Cart)Session ["cart"]; System.Diagnostics.Debug.WriteLine("Retreived cart"); } cart.AddProduct(new Product(reader.GetUInt64("productID"), reader.GetUInt64("categoryID"), reader.GetString("productName"), reader.GetString("categoryName"), reader.GetString("productShortDescription"), reader.GetString("productLongDescription"), reader.GetDouble("productPrice"), reader.GetDouble("productSalePrice"), reader.GetBoolean("productOnSale"), reader.GetDateTime("productAdded"))); System.Diagnostics.Debug.WriteLine("Added product to cart"); Response.Redirect("~/Site/Cart.aspx"); } } } }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { return; } if (Session ["user"] == null) { Response.Redirect("~/Site/Login.aspx"); } if (Session ["cart"] == null) { Session ["cart"] = new Classes.Cart(); } cart.DataSource = ((Classes.Cart)Session ["cart"]).Products; cart.DataBind(); }