// Adds current product to cart; gets shopping cart model from session and updates (then writes back to session). protected void btnAddToCart_Click(object sender, EventArgs e) { if (IsValid) { BLProduct productData = Session["Product"] as BLProduct; BLShoppingCart cart = HttpContext.Current.Session["Cart"] as BLShoppingCart; bool existingItem = false; foreach (BLCartItem item in cart.Items) { if (item.Product.prodNumber == productData.prodNumber && item.Size == rblSizeOption.SelectedItem.Value) { item.Quantity += Convert.ToInt32(tbxQuantity.Text); existingItem = true; break; } } if (!existingItem) { cart.AddCartItem(new BLCartItem(productData, rblSizeOption.SelectedItem.Value, Convert.ToInt32(tbxQuantity.Text))); } Response.Redirect("~/UL/Cart"); } }
protected void Page_Load(object sender, EventArgs e) { // Check for secure connection if (Request.IsSecureConnection) { // Page is not viewable on admin site if (!Session["LoginStatus"].Equals("Admin")) { // Calculate total cost of the cart int total = 0; BLShoppingCart cart = Session["Cart"] as BLShoppingCart; // Display updated cost Cost.Text = string.Format("{0:C}", cart.Amount); } else { Response.Redirect("~/UL/ErrorPage/5"); } } else { // Make connection secure if it isn't already string url = ConfigurationManager.AppSettings["SecurePath"] + "Cart"; Response.Redirect(url); } }
// Attaches total cost of cart as parameter and redirects to payment form protected void btnCheckout_Click(object sender, EventArgs e) { BLShoppingCart cart = Session["Cart"] as BLShoppingCart; // Cannot checkout unless items are in the cart if (!cart.isEmpty()) { string cartTotal = Cost.Text; Session["Cost"] = cartTotal; if (Session["LoginStatus"].ToString().Equals("LoggedOut")) { // Unable to checkout without a registered account Response.Redirect("~/UL/ErrorPage/4"); } else { Response.Redirect("~/UL/Payment"); } } else { ErrorLabel.Text = "Cannot perform checkout with no items in cart."; } }
public void GivenACartAndABalanceWhenQueriedTheCountOfItemsDrivenIntoNegativeBalanceReflectsTheCartAndTheBalance() { var sut = new BLShoppingCart(); sut.AddSomeItems(); sut.CountOfItemsDrivenIntoNegativeBalance(5.00M).Should().Be(2); }
public void WhenItemsAreAddedToTheCartThenTheRunningSubTotalPricesReflectThoseItems() { var expected = new List <decimal> { 1.15M, 6.65M, 7.75M }; var sut = new BLShoppingCart(); sut.AddSomeItems(); sut.RunningSubTotalPrices().ShouldAllBeEquivalentTo(expected); }
protected void Page_Load(object sender, EventArgs e) { // Check for secure connection if (Request.IsSecureConnection) { // Page only available to logged in user if (Session["LoginStatus"].Equals("User")) { // Check if items are still in the cart - otherwise; wrong state BLShoppingCart cart = Session["Cart"] as BLShoppingCart; if (!cart.isEmpty()) { if (!IsPostBack) { double amount = Convert.ToDouble((Session["Cart"] as BLShoppingCart).Amount); lblAmount.Text = string.Format("{0:C}", amount); ddlShipping.DataSource = BLShipping.getShippingMethods(); ddlShipping.DataBind(); BLUser user = Session["CurrentUser"] as BLUser; lblFirst.Text = user.userFirstName; lblLast.Text = user.userLastName; lblBillStreet.Text = user.billAddress.addStreet; lblBillSuburb.Text = user.billAddress.addSuburb; lblBillState.Text = user.billAddress.addState; lblBillZip.Text = user.billAddress.addZip.ToString(); lblPostStreet.Text = user.postAddress.addStreet; lblPostSuburb.Text = user.postAddress.addSuburb; lblPostState.Text = user.postAddress.addState; lblPostZip.Text = user.postAddress.addZip.ToString(); } } else { Response.Redirect("~/UL/ErrorPage/7"); } } else { Response.Redirect("~/UL/ErrorPage/0"); } } else { // Make connection secure if it isn't already string url = ConfigurationManager.AppSettings["SecurePath"] + "Payment"; Response.Redirect(url); } }
protected void Page_Load(object sender, EventArgs e) { // Check for secure connection if (Request.IsSecureConnection) { // Page only accessible to a logged in user if (Session["LoginStatus"].Equals("User")) { // Check if items are still in the cart - otherwise; wrong state BLShoppingCart cart = Session["Cart"] as BLShoppingCart; if (!cart.isEmpty()) { // Send confirmation of order to account email address BLShipping shipping = Session["Shipping"] as BLShipping; string mailbody = BLPurchase.generateOrderSummary(Session["Name"].ToString(), cart, shipping); try { BLEmail.SendEmail(Session["UserName"].ToString(), "Order Receipt - JerseySure", mailbody); } catch (Exception ex) { Response.Redirect("~/UL/ErrorPage/1"); } // Remove cart from session Session.Remove("Cart"); Session["Cart"] = new BLShoppingCart(); } else { Response.Redirect("~/UL/ErrorPage/7"); } } else { Response.Redirect("~/UL/ErrorPage/0"); } } else { // Make connection secure if it isn't already string url = ConfigurationManager.AppSettings["SecurePath"] + "PaymentConfirmation"; Response.Redirect(url); } }
public static void AddSomeItems(this BLShoppingCart cart) { var shoppingCartItems = new List <ShoppingCartItem> { new ShoppingCartItem(new Product { Fees = 0.05M, Price = 1.00M, TaxRate = 0.10M, ProductName = "a" }, 1, 1, 1), // 1.15 new ShoppingCartItem(new Product { Fees = 0.00M, Price = 5.00M, TaxRate = 0.10M, ProductName = "b" }, 1, 2, 1), // 1.15 + 5.50 = 6.65 new ShoppingCartItem(new Product { Fees = 0.00M, Price = 1.00M, TaxRate = 0.10M, ProductName = "c" }, 1, 3, 1), // 6.65 + 1.10 = 7.75 }; shoppingCartItems.ForEach(cart.AddProductById); }
// Remove specified cart item from the shopping cart protected void btnRemove_Click(object sender, EventArgs e) { BLShoppingCart cart = Session["Cart"] as BLShoppingCart; CheckBox selected; ListViewDataItem currDataItem; // Finds specified cart item within the overall cart and removes it for (int i = ItemList.Items.Count - 1; i >= 0; i--) { currDataItem = ItemList.Items[i]; selected = currDataItem.FindControl("cbxRemove") as CheckBox; if (selected.Checked) { cart.Items.RemoveAt(ItemList.Items[i].DisplayIndex); cart.calculate(); } } Response.Redirect("~/UL/Cart"); }
protected void Page_Load(object sender, EventArgs e) { if (!Request.IsSecureConnection) { // Page not accessible on admin site if (!Session["LoginStatus"].Equals("Admin")) { BLProduct product = new BLProduct(); BLShoppingCart cart = Session["Cart"] as BLShoppingCart; product = product.selectProduct(Session["productNumber"].ToString()); Session["Product"] = product; lblTitle.Text = product.playFirstName + " " + product.playLastName + " " + product.teamLocale + " " + product.teamName; lblDescription.Text = product.prodDescription; lblPrice.Text = string.Format("{0:C0}", product.prodPrice); imgFront.ImageUrl = "Images\\jerseys\\" + product.image[0]; imgBack.ImageUrl = "Images\\jerseys\\" + product.image[1]; if (cart != null) { if (cart.Items.Count > 0) { foreach (BLCartItem item in cart.Items) { if (item.Product.prodNumber == product.prodNumber) { switch (item.Size) { case "S": product.stock[0] -= item.Quantity; break; case "M": product.stock[1] -= item.Quantity; break; case "L": product.stock[2] -= item.Quantity; break; case "XL": product.stock[3] -= item.Quantity; break; case "XXL": product.stock[4] -= item.Quantity; break; } } } } } rblSizeOption.Items[0].Enabled = product.stock[0] > 0; rblSizeOption.Items[1].Enabled = product.stock[1] > 0; rblSizeOption.Items[2].Enabled = product.stock[2] > 0; rblSizeOption.Items[3].Enabled = product.stock[3] > 0; rblSizeOption.Items[4].Enabled = product.stock[4] > 0; btnAddToCart.Visible = tbxQuantity.Visible = rblSizeOption.Visible = product.stock.Sum() > 0; csvQuantity.Enabled = rfvQuantity.Enabled = rxvQuantity.Enabled = rfvSize.Enabled = product.stock.Sum() > 0; lblNoStock.Visible = product.stock.Sum() == 0; } else { Response.Redirect("~/UL/ErrorPage/5"); } } else { // Make connection unsecured if it isn't already string url = ConfigurationManager.AppSettings["UnsecurePath"] + "SingleProductPage"; Response.Redirect(url); } }
private void ClearFields() { this.created = DateTime.MinValue; this.uid = string.Empty; this.saveInfo = false; this.creditCard = null; this.billingAddress = null; this.shippingAddress = null; this.shoppingCart = null; this.category = null; this.billingAddress = new BLAddress(); this.shippingAddress = new BLAddress(); this.shoppingCart = new BLShoppingCart(); this.creditCard = new BLCreditCard(); this.items = new BLItems(); this.orders = new BLOrders(); this.category = new BLCategory(); this.item = new BLItem(); }
public void Retrieve() { DataSet dsitems; //////////////////// dsitems= GetOrgList( , "S", "get_Orgs", this.ID, ""); dsKnow = r.get_orgKnow("get_orgKnow", "S", this.ID, ""); if( this.uid.Length > 0 ) dsitems = DALCCustomer.GetItemBySessionID(this.uid); else dsitems = DALCCustomer.GetItem(this.id); if( dsitems.Tables.Count > 0 && dsitems.Tables[0].Rows.Count > 0) { this.id = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["ID"] ); this.uid = Convert.ToString( dsitems.Tables["Customer"].Rows[0]["SessionID"] ); this.created = Convert.ToDateTime( dsitems.Tables["Customer"].Rows[0]["Created"] ); this.saveInfo = Convert.ToBoolean( dsitems.Tables["Customer"].Rows[0]["SaveInfo"] ); int creditCardID = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["CreditCardInfoID"] ); int billingInfoID = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["BillingAddressID"] ); int shippingInfoID = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["ShippingAddressID"] ); if( creditCardID > 0) { creditCard = new BLCreditCard(); creditCard.ID = creditCardID; creditCard.Retrieve(); } if( billingInfoID > 0 ) { billingAddress = new BLAddress(); billingAddress.ID = billingInfoID; billingAddress.Retrieve(); } if( shippingInfoID > 0 ) { shippingAddress = new BLAddress(); shippingAddress.ID = shippingInfoID; shippingAddress.Retrieve(); } if (shoppingCart == null) { shoppingCart = new BLShoppingCart(); } shoppingCart.CustomerID = this.id; shoppingCart.Retrieve(); if(items == null) { items = new BLItems(); } items.OrgID = this.id; items.Retrieve(); } else { this.id = 0; ClearFields(); } }
// Initialises shopping cart object in the session to empty protected void btnEmptyCart_Click(object sender, EventArgs e) { Session.Remove("Cart"); Session["Cart"] = new BLShoppingCart(); Response.Redirect(Request.Url.ToString(), true); }
// Returns currently stored cart items in the session public List <BLCartItem> GetCartItems() { BLShoppingCart cart = Session["Cart"] as BLShoppingCart; return(cart.Items); }
private void ClearFields() { this.created = DateTime.MinValue; this.uid = string.Empty; this.saveInfo = false; this.creditCard = null; this.billingAddress = null; this.shippingAddress = null; this.shoppingCart = null; this.billingAddress = new BLAddress(); this.shippingAddress = new BLAddress(); this.shoppingCart = new BLShoppingCart(); this.creditCard = new BLCreditCard(); this.organization = new BLOrganization(); this.organizationhld = new BLOrganization(); }
public void Retrieve() { DataSet dsitems; if( this.uid.Length > 0 ) dsitems = DALCCustomer.GetItemBySessionID(this.uid); else dsitems = DALCCustomer.GetItem(this.id); if( dsitems.Tables.Count > 0 && dsitems.Tables[0].Rows.Count > 0) { this.id = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["ID"] ); this.uid = Convert.ToString( dsitems.Tables["Customer"].Rows[0]["SessionID"] ); this.created = Convert.ToDateTime( dsitems.Tables["Customer"].Rows[0]["Created"] ); this.saveInfo = Convert.ToBoolean( dsitems.Tables["Customer"].Rows[0]["SaveInfo"] ); int creditCardID = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["CreditCardInfoID"] ); int billingInfoID = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["BillingAddressID"] ); int shippingInfoID = Convert.ToInt32( dsitems.Tables["Customer"].Rows[0]["ShippingAddressID"] ); if (organization == null) { organization = new BLOrganization(); } if( creditCardID > 0) { creditCard = new BLCreditCard(); creditCard.ID = creditCardID; creditCard.Retrieve(); } if( billingInfoID > 0 ) { billingAddress = new BLAddress(); billingAddress.ID = billingInfoID; billingAddress.Retrieve(); } if( shippingInfoID > 0 ) { shippingAddress = new BLAddress(); shippingAddress.ID = shippingInfoID; shippingAddress.Retrieve(); } if(shoppingCart == null) { shoppingCart = new BLShoppingCart(); } shoppingCart.CustomerID = this.id; shoppingCart.Retrieve(); if(organization == null) { organization = new BLOrganization(); } ///////////organization.ID = messages.orgID; organization.Retrieve();/// = new BLShoppingCart(); /// messages.cust = this ; /// messages.org = organization; } else { this.id = 0; ClearFields(); } }