Ejemplo n.º 1
0
        public ActionResult Checkout([Bind(Include = "FirstName,LastName,Address,City,AreaCode,PhoneNumber")] Order order)
        {
            List <Item> cart = (List <Item>)Session["cart"];

            if (ModelState.IsValid)
            {
                order.OrderPlaced = DateTime.Now;
                decimal?total = 0m;
                decimal?l     = 0m;
                foreach (var item in cart)
                {
                    l      = item.Product.Price * item.Quantity;
                    total += l;
                }
                order.OrderTotal    = total;
                order.OrderComplete = false;

                ctx.Orders.Add(order);


                ctx.SaveChanges();

                foreach (var shoppingCartItem in cart)
                {
                    var orderDetail = new OrderDetail
                    {
                        Amount    = shoppingCartItem.Quantity,
                        Price     = shoppingCartItem.Product.Price,
                        ProductId = shoppingCartItem.Product.ProductId,
                        OrderId   = order.OrderId
                    };
                    ctx.OrderDetails.Add(orderDetail);
                }
                ctx.SaveChanges();
                OrdersHub.BroadcastData();
                Session["cart"] = null;
            }
            return(RedirectToAction("PaymentWithPaypal", "Payment"));
        }