Exemple #1
0
        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");

            }
        }
        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;
            }
        }
Exemple #3
0
 public List<Cart> GetShoppingCartItems()
 {
     ShoppingCartActions actions = new ShoppingCartActions();
     return actions.GetCartItems();
 }