public void AddOrder(Order order)
 {
     if (order.OrderID == 0)
     {
         context.Orders.Add(order);
     }
     else
     {
         Order dbEntry = context.Orders.Find(order.OrderID);
         if (dbEntry != null)
         {
             dbEntry.Cart = order.Cart;
             dbEntry.Delivery = order.Delivery;
             dbEntry.Payment = order.Payment;
             dbEntry.StartDate = order.StartDate;
             dbEntry.StopDate = order.StopDate;
             dbEntry.OrderStatus = order.OrderStatus;
             dbEntry.PayStatus = order.PayStatus;
             dbEntry.UserID = order.UserID;
         }
     }
     context.SaveChanges();
 }
        public ActionResult PayOrder(Order order)
        {
            if (ModelState.IsValid)
            {
                order.PayStatus = "Pay";
                switch (order.Delivery)
                {
                    case "OneSelf":
                        order.OrderStatus = "Expects the buyer";
                        break;
                    case "InHome":
                        order.OrderStatus = "Expects delivery";
                        break;
                };
                repository.UpdatePayStatus(order.OrderID, order.PayStatus);
                repository.UpdateOrderStatus(order.OrderID, order.OrderStatus);
                    return RedirectToAction("Index");
            }
            else
            {
               return View(order);
            }

        }
        public ActionResult MakeOrder(Order order, Cart cart, OrderPayment orderPayment, OrderDelivery orderDelivery)
        {   
            if (cart.Lines.Count() != 0)
            {
                order.Payment = orderPayment.Payment;
                order.Delivery = orderDelivery.Delivery;
                order.Cart = JsonConvert.SerializeObject(cart);
                order.TotalPrice = cart.ComputeTotalValue();
                order.UserID = WebSecurity.CurrentUserId;
                {
                    if (ModelState.IsValid)
                    {
                        repository.AddOrder(order);
                    }
                }
                cart.Clear();
                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }

        }