protected void Page_Load(object sender, EventArgs e) { items = (List <CartItem>)Session["cartItems"]; if (!IsPostBack) { if (items.Count <= 0) { Response.Redirect("~/"); } } if (items.Count <= 0) { Response.Redirect("~/"); } foreach (var item in items) { int bookId = BusinessLogic.GetBookID(item.Isbn); string title = BusinessLogic.GetBookTitle(bookId); int quantity = item.Quantity; decimal price = BusinessLogic.GetPrice(bookId); decimal discount = (BusinessLogic.GetPrice(bookId) - BusinessLogic.GetDiscountedPrice(bookId)) * quantity; decimal subtotal = price * quantity - discount; CartModel model = new CartModel(title, price, quantity, discount, subtotal); models.Add(model); } gvCart.DataSource = models; gvCart.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { Session["total"] = String.Empty; Session["discountTotal"] = String.Empty; Session["discountedTotal"] = String.Empty; decimal total = 0; string promoCode = (string)Session["promoCode"]; items = (List <CartItem>)Session["cartItems"]; if (items.Count <= 0) { Response.Redirect("~/"); } else { foreach (var item in items) { int bookId = BusinessLogic.GetBookID(item.Isbn); string title = BusinessLogic.GetBookTitle(bookId); int quantity = item.Quantity; decimal price = BusinessLogic.GetPrice(bookId); decimal discount = (BusinessLogic.GetPrice(bookId) - BusinessLogic.GetDiscountedPrice(bookId)) * quantity; decimal subtotal = price * quantity - discount; total += subtotal; CartModel model = new CartModel(title, price, quantity, discount, subtotal); models.Add(model); } Session["total"] = total.ToString("c2"); Session["discountTotal"] = (total - BusinessLogic.GetTotalPromoPriceFromCart(items, promoCode)).ToString("c2"); Session["discountedTotal"] = BusinessLogic.GetTotalPromoPriceFromCart(items, promoCode).ToString("c2"); gvCart.DataSource = models; gvCart.DataBind(); } }
protected void btnPlus_Click(object sender, EventArgs e) { LinkButton btn = (LinkButton)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; int qty = items[row.RowIndex].Quantity + 1; if (qty > BusinessLogic.GetQty(BusinessLogic.GetBookID(items[row.RowIndex].Isbn))) { pnlError.Visible = true; } else { items[row.RowIndex].Quantity += 1; Session["cartItem"] = items; Response.Redirect("~/Cart"); } }
protected void Page_Load(object sender, EventArgs e) { string isbn = Request.QueryString["ISBN"]; Bookshop context = new Bookshop(); int bookid = BusinessLogic.GetBookID(isbn); if (isbn != null) { string img = context.Book.Single(x => x.BookID == bookid).Image; string n = string.Format("~/images/" + img); Image1.ImageUrl = n; Book cn = BusinessLogic.GetBook(isbn); decimal NormalPrice = BusinessLogic.GetPrice(bookid); decimal DiscountedPrice = BusinessLogic.GetDiscountedPrice(bookid); Title_lbl.Text = cn.Title; Author_lbl.Text = cn.Author; Category_lbl.Text = BusinessLogic.GetCategoryName(isbn); NormalPrice_lbl.Text = NormalPrice.ToString("c2"); if (NormalPrice == DiscountedPrice) { NormalPrice_lbl.Font.Strikeout = false; Discounted_lbl.Visible = false; } else { NormalPrice_lbl.Font.Strikeout = true; Discounted_lbl.Text = BusinessLogic.GetDiscountedPrice(bookid).ToString("c2"); Discounted_lbl.Visible = true; } Warning_lbl.Visible = false; } }