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); }
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>"); } }