Exemple #1
0
        private void GetTotalPrice()
        {
            AddToCart objAddToCart = new AddToCart();
            string    cartID       = objAddToCart.GetShoppingCartId();

            decimal cartTotal = GetTotal(cartID);

            lblTotalOrder.Text = string.Format("Rp.{0:N0}", cartTotal);
        }
        private void GetTotalPrice()
        {
            AddToCart objAddToCart = new AddToCart();
            string    cartID       = objAddToCart.GetShoppingCartId();

            decimal cartTotal = GetTotal(cartID);

            lblTotalOrder.Text = string.Format("Rp.{0:N0}", cartTotal);
            if (cartTotal == 0)
            {
                btnCheckout.Visible = false;
            }
        }
Exemple #3
0
        public bool SubmitOrder(string username)
        {
            try
            {
                Order newOrder = new Order()
                {
                    CustomerName = username,
                    OrderDate    = DateTime.Now,
                    ShipDate     = HitungTanggalKirim()
                };
                var addResult = db.Orders.Add(newOrder);
                db.SaveChanges();
                orderId = addResult.OrderID;

                //menambahkan data order detail
                AddToCart objAddCart = new AddToCart();
                string    cartID     = objAddCart.GetShoppingCartId();
                var       results    = from s in db.ShoppingCarts.Include("Book")
                                       where s.CartID == cartID
                                       select s;
                foreach (var shoppingCart in results)
                {
                    OrderDetail od = new OrderDetail()
                    {
                        OrderID  = newOrder.OrderID,
                        BookID   = shoppingCart.BookID,
                        Quantity = shoppingCart.Quantity,
                        Price    = shoppingCart.Book.Price
                    };
                    db.OrderDetails.Add(od);

                    //mendelete data pada ShoppingCart
                    var result = (from s in db.ShoppingCarts
                                  where s.CartID == shoppingCart.CartID && s.BookID == shoppingCart.BookID
                                  select s).SingleOrDefault();
                    if (result != null)
                    {
                        db.ShoppingCarts.Remove(result);
                    }
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(true);
        }