public ViewResult ConfirmCheckout(Cart cart, int deliveryId)
        {
            Delivery delivery = deliveryRepository.Deliveries.FirstOrDefault(d => d.DeliveryId == deliveryId);
            Order order = new Order();
            order.PriceBeforeVouchers = cart.GetTotalValue();
            order.UserId = WebSecurity.CurrentUserId;
            order.TimeSubmitted = DateTime.Now;
            
            order.DeliveryId = deliveryId;
            order.Subtotal = order.PriceBeforeVouchers + delivery.Cost;
            order.Total = order.Subtotal;
            order.Status = "Processed";
            orderRepository.SaveOrder(order);
            int orderId = orderRepository.Orders.FirstOrDefault(o => o.TimeSubmitted == order.TimeSubmitted).OrderId;
            List<Pizza> pizzas = new List<Pizza>();

            foreach(var cartLine in cart.Lines){
                for(int i=0;i<cartLine.Quantity;i++)
                {
                    Orderline orderline = new Orderline();
                    orderline.PizzaId = cartLine.Pizza.PizzaId;
                    orderline.OrderlinePrice = cartLine.Pizza.Price * cartLine.Quantity;
                    orderline.UserId = WebSecurity.CurrentUserId;
                    orderline.OrderId = order.OrderId;
                    orderlineRepository.SaveOrderline(orderline);
                    pizzas.Add(repository.Pizzas.FirstOrDefault(p => p.PizzaId == orderline.PizzaId));
                    Pizza pizza = repository.Pizzas.FirstOrDefault(p => p.PizzaId == orderline.PizzaId);
                    if (pizza.Name == "Create Your Own")
                    {
                        foreach (var topping in Session["ToppingList"] as List<Topping>)
                        {
                            PizzaToppingOrder pizzaToppingOrder = new PizzaToppingOrder();
                            pizzaToppingOrder.OrderlineId = orderline.OrderlineId;
                            pizzaToppingOrder.ToppingId = topping.ToppingId;
                            pizzaToppingOrderRepository.SavePizzaToppingOrder(pizzaToppingOrder);
                        }
                    }
                }
            }

            cart.Clear();
            ViewBag.PriceBeforeVouchers = order.PriceBeforeVouchers;
            
            ViewBag.DeliveryCost = delivery.Cost;
            ViewBag.PriceIncDelivery = order.PriceBeforeVouchers + delivery.Cost;
            ViewBag.DeliveryType = delivery.DeliveryType;
            
            var context = new UsersContext();
            var username = User.Identity.Name;
            var user = context.UserProfiles.SingleOrDefault(u => u.UserName == username);

            List<Topping> toppings = Session["ToppingList"] as List<Topping>;

            return View(new ConfirmCheckoutViewModel
            {
                User = user,
                Order = order,
                Pizzas =  pizzas, //orderlineRepository.Orderlines.Where(ol => ol.OrderId == order.OrderId).ToList()
                Toppings = toppings
            });
            //return View(user);
        }
        public void CalcCartTotal()
        {
            //Arrange
            Pizza p1 = new Pizza { PizzaId = 1, Name = "Pizza1", Price = 5M };
            Pizza p2 = new Pizza { PizzaId = 2, Name = "Pizza2", Price = 3.50M };
            Pizza p3 = new Pizza { PizzaId = 3, Name = "Pizza3", Price = 51M };
            Cart cart = new Cart();

            //Action
            cart.AddItem(p1, 1);
            cart.AddItem(p2, 2);
            cart.AddItem(p3, 1);
            decimal result = cart.GetTotalValue();

            //Assert
            Assert.AreEqual(result, 63M);
        }