public decimal countprice(CartList cl) { List <Cart> cart = cl.getCl(); decimal totalprice = 0; for (int i = 0; i < cart.Count; i++) { Cart c = cart[i]; decimal p = 0; p = c.b.Price; totalprice = totalprice + p; } return(totalprice); }
protected void btnCheckOut_Click(object sender, EventArgs e) { //For Luke //if (Session["username"] == null) //{ // Response.Redirect("Login.aspx"); //} CartList cart = (CartList)Session["cart"]; cc.minusStock(cart); Session["cart"] = null; Response.Write("<script>alert('Update Successful!');window.location.href ='Homepage.aspx'</script>"); }
public CartList addItem(CartList cl, int id, string t, decimal p) { Book b = new Book(); b.BookID = id; b.Title = t; b.Price = p; int q = 1; Cart c = new Cart(b, q); cl.add(c); CartList Cl = cl; return(Cl); }
public void minusStock(CartList cl) { BookshopEntities bookshop = new BookshopEntities(); List <Cart> cart = cl.getCl(); for (int i = 0; i < cart.Count; i++) { Cart c = cart[i]; Book b = bookshop.Books.Find(c.b.BookID); int bookstock = 1; bookstock = b.Stock - 1; b.Stock = bookstock; bookshop.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["cart"] != null) { CartList cart = (CartList)Session["cart"]; this.GridViewCart.DataSource = cart.getCl(); this.GridViewCart.DataBind(); decimal totalprice = cc.countprice(cart); txtTotalPrice.Text = totalprice.ToString(); } else { CartList cart = new CartList(); this.GridViewCart.DataSource = cart.getCl(); this.GridViewCart.DataBind(); decimal totalprice = cc.countprice(cart); txtTotalPrice.Text = totalprice.ToString(); Response.Write("<script>alert('Empty!')</script>"); } }
protected void btnAddToCart_Click(object sender, EventArgs e) { shopController sc = new shopController(); string title = (string)Session["booktitle"]; Book b = sc.loadBook(title); //For Luke's login part //if (Session["username"] == null) //{ // Response.Redirect("Login.aspx"); //} if (Session["cart"] != null) { CartList cl = (CartList)Session["cart"]; int id = b.BookID; decimal price = 0; price = b.Price; cartController cc = new cartController(); cl = cc.addItem(cl, id, title, price); Session["cart"] = cl; } else { CartList cl = new CartList(); int id = b.BookID; decimal price = 0; price = b.Price; cartController cc = new cartController(); cl = cc.addItem(cl, id, title, price); Session["cart"] = cl; } Response.Redirect("ViewCart.aspx"); }