//Checkout Button (only visible if gridview has data) protected void btnCheckout_Click(object sender, EventArgs e) { shoppingCart = (ArrayList)Session["ShoppingCart"]; JavaScriptSerializer js = new JavaScriptSerializer(); APICalls api = new APICalls(); SPCaller spc = new SPCaller(); Customer c = new Customer(); c.Email = Session["Username"].ToString(); c.CustomerID = spc.GetCustomerIDByEmail(c.Email); //Adding each product into the database foreach (Product p in shoppingCart) { //String jsonCheckout = js.Serialize(p); try { bool data = api.RecordPurchase(url, p.ID.ToString(), p.Quantity, "1", "0", DateTime.Now.ToString(), DateTime.Now.TimeOfDay.ToString(), c); if (data == true) { Response.Redirect("Confirmation.aspx", false); } else { lblMessage.Text = "A problem occurred while checking out."; } } catch (Exception ex) { lblMessage.Text = "Error: " + ex.Message; } } }
//For Record Purchase protected void btnSubmit1_Click(object sender, EventArgs e) { lblResult1.Text = ""; if (val.isValidNumber(txtProductID.Text) && val.isValidNumber(txtQuantity.Text) && val.isValidNumber(txtSellerSiteID.Text) && !string.IsNullOrWhiteSpace(txtInputAPIKey.Text)) { try { WebRequest request = WebRequest.Create(url + "Rec/" + txtProductID.Text + "/" + txtQuantity.Text + "/" + txtSellerSiteID.Text + "/" + txtInputAPIKey.Text + "/"); bool data = api.RecordPurchase(url, txtProductID.Text, int.Parse(txtQuantity.Text), txtSellerSiteID.Text, txtInputAPIKey.Text, custInfo); if (data == true) { lblResult1.Text = "True"; txtProductID.Text = ""; txtQuantity.Text = ""; txtSellerSiteID.Text = ""; txtInputAPIKey.Text = ""; } else { lblResult1.Text = "False"; } } catch (Exception ex) { lblResult1.Text = "Error: " + ex.Message; } } else { if (!val.isValidNumber(txtProductID.Text)) { lblResult1.Text += "<br>You entered an invalid Product ID. Numbers only."; } if (!val.isValidNumber(txtQuantity.Text)) { lblResult1.Text += "<br>You entered an invalid Quantity. Numbers only."; } if (!val.isValidNumber(txtSellerSiteID.Text)) { lblResult1.Text += "<br>You entered an invalid Seller ID. Numbers only."; } if (string.IsNullOrWhiteSpace(txtInputAPIKey.Text)) { lblResult.Text += "<br>You entered an invalid APIKey. It should include numbers or letters only."; } } }