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(); } }
private void LoadDiscountedPrice() { foreach (ListViewDataItem b in ListView1.Items) { int bookId = Convert.ToInt32((b.FindControl("IdLabel1") as Label).Text); (b.FindControl("IdLabel1") as Label).Visible = false; (b.FindControl("PriceLabel2") as Label).Text = BusinessLogic.GetDiscountedPrice(bookId).ToString("c2"); (b.FindControl("PriceLabel1") as Label).Text = BusinessLogic.GetPrice(bookId).ToString("c2"); if (BusinessLogic.GetPrice(bookId) == BusinessLogic.GetDiscountedPrice(bookId)) { (b.FindControl("PriceLabel2") as Label).Visible = false; } else { (b.FindControl("PriceLabel1") as Label).Text = "<del>" + BusinessLogic.GetPrice(bookId).ToString("c2") + "</del>"; (b.FindControl("PriceLabel2") as Label).Text = " " + BusinessLogic.GetDiscountedPrice(bookId).ToString("c2"); } } }
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; } }