public ShoppingCartActions GetCart() { using (var cart = new ShoppingCartActions()) { cart.ShoppingCartId = cart.GetCartId(); return cart; } }
protected void Page_Load(object sender, EventArgs e) { using (usersShoppingCart = new ShoppingCartActions()) { decimal cartTotal = 0; cartTotal = usersShoppingCart.GetTotal(); lblTotal.Text = String.Format(CultureInfo.GetCultureInfo("vi-VN"), "{0:c0}", cartTotal); } }
protected void submit_Click(object sender, EventArgs e) { db = new eWorldEntities(); using (usersShoppingCart = new ShoppingCartActions()) { List<Cart> c = usersShoppingCart.GetCartItems(); Order order = new Order(); order.OrderDate = c[0].DateCreated; order.Email = HttpContext.Current.User.Identity.Name; order.Total = Convert.ToDouble(usersShoppingCart.GetTotal()); order.paid = false; db.Orders.Add(order); db.SaveChanges(); OrderDetail orderdetail; int num = c.Count; for (int i = 0; i < num; i++) { orderdetail = new OrderDetail(); orderdetail.OrderID = order.OrderID; orderdetail.ProductID = c[i].ProductID; orderdetail.Quantity = c[i].Quantity; orderdetail.UnitPrice = c[i].Product.Price; db.OrderDetails.Add(orderdetail); db.SaveChanges(); } string ShoppingCartId = usersShoppingCart.GetCartId(); var cartItems = db.Carts.Where( ci => ci.CartID == ShoppingCartId); foreach (var cartItem in cartItems) { db.Carts.Remove(cartItem); } // Save changes. db.SaveChanges(); Response.Redirect("Checkout_success"); } }
protected void Page_Load(object sender, EventArgs e) { { string rawId = Request.QueryString["ProductID"]; int productId; if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId)) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { usersShoppingCart.AddToCart(Convert.ToInt16(rawId)); } } else { Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId."); throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId."); } Response.Redirect("ShoppingCart.aspx"); } }
public List<Cart> UpdateCartItems() { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { String cartId = usersShoppingCart.GetCartId(); usersShoppingCart.UpdateShoppingCartDatabase(cartId, getcartUpdate()); CartList.DataBind(); lblTotal.Text = String.Format(CultureInfo.GetCultureInfo("vi-VN"), "{0:c0}", usersShoppingCart.GetTotal()); List<Cart> result = usersShoppingCart.GetCartItems(); if (result.Count == 0) { LabelTotalText.Text = ""; lblTotal.Text = ""; Title_EmptyCart.Visible = true; Checkout_btn.Visible = false; Update_btn.Visible = false; } return result; } }
protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { usersShoppingCart.EmptyCart(); Context.GetOwinContext().Authentication.SignOut(); } }
protected void Page_PreRender(object sender, EventArgs e) { using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions()) { string cartStr = string.Format("Giỏ hàng ({0})", usersShoppingCart.GetCount()); cartCount.InnerText = cartStr; } }
public List<Cart> GetShoppingCartItems() { ShoppingCartActions actions = new ShoppingCartActions(); return actions.GetCartItems(); }
protected void Page_Load(object sender, EventArgs e) { using (usersShoppingCart = new ShoppingCartActions()) { decimal cartTotal = 0; cartTotal = usersShoppingCart.GetTotal(); if (cartTotal > 0) { // Display Total. lblTotal.Text = String.Format(CultureInfo.GetCultureInfo("vi-VN"), "{0:c0}", cartTotal); Title_EmptyCart.Visible = false; } else { LabelTotalText.Text = ""; lblTotal.Text = ""; Title_EmptyCart.Visible = true; Checkout_btn.Visible = false; Update_btn.Visible = false; } } }