public ActionResult Index(Order order)
 {
     //is the user logged in?
     if (Request.IsAuthenticated)
     {
         //you cannot check out an empty cart
         Cart cart = Assignment2MVC.Models.Cart.getCart();
         if (cart.GetSize() == 0)
         {
             ViewBag.Error = "You cannot checkout an empty cart";
             return View();
         }
         //get the user who is checking out
         int uid = WebSecurity.GetUserId(User.Identity.Name);
         UserProfile user = users.UserProfiles.FirstOrDefault(u => u.UserId == uid);
         //fill in some of the order fields
         order.Date = DateTime.Now;
         order.Total = cart.GetTotal();
         order.UserID = uid;
         //add the order
         if (ModelState.IsValid)
         {
             db.Orders.Add(order);
         }
         else
         {
             ViewBag.Error = "Error some incorrect data was entered";
             return View();
         }
         //create the order lines for this order
         List<OrderLine> lines = new List<OrderLine>();
         foreach (CartItem item in cart.cartItems)
         {
             OrderLine line = new OrderLine();
             line.ProductID = item.product.ProductID;
             line.product = item.product;
             db.Products.Attach(line.product);
             line.quantity = item.quantity;
             line.OrderID = order.OrderID;
             line.order = order;
             db.OrderLines.Add(line);
             lines.Add(line);
         }
         //save changes
         
         db.SaveChanges();
         SummaryViewModel vm = new SummaryViewModel(lines, order, user);
         cart.Empty();
         return View("Summary", vm);
     }
     else
     {
         return RedirectToAction("Login", "Account");
     }
 }
 public SummaryViewModel(List<OrderLine> lines, Order o, UserProfile p)
 {
     this.OrderLines = lines;
     this.Order = o;
     this.Profile = p;
 }