public HttpResponseMessage PostOrderedItem(OrderedItem orderedItem)
 {
     try
     {
         var OrderedItemAdded = _repository.InsertOrderedItem(orderedItem);
         return Request.CreateResponse<OrderedItem>(HttpStatusCode.Created, OrderedItemAdded);
     }
     catch (Exception ex)
     {
         return Request.CreateResponse(HttpStatusCode.NotImplemented, ex);
     }
 }
 public HttpResponseMessage DeleteOrderedItem(OrderedItem orderedItem)
 {
     try
     {
         var OrderedItemDeleted = _repository.InsertOrderedItem(orderedItem);
         return Request.CreateResponse<OrderedItem>(HttpStatusCode.OK, OrderedItemDeleted);
     }
     catch (Exception ex)
     {
         return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
     }
 }
 //[HttpGet]
 //[Route("selectedMenuItem/{menuItemId}")]
 public PartialViewResult SelectedMenuItem(int menuItemId, int customerId)
 {
     var theMenuItem = _repository.GetMenuItemById(menuItemId);
     ViewData["CustomerId"] = customerId;
     ViewData["MenuItem"] = theMenuItem;
     ViewData["OrderedItem"] = new OrderedItem();
     return PartialView("SelectedMenuItem", theMenuItem);
 }
 public JsonResult PlaceOrder()
 {
     if ((Session["orderedItems"] as List<OrderedItem>) == null)
     {
         Session["orderedItems"] = new List<OrderedItem>();
     }
     if ((Session["modelSaved"] as List<OrderedItem>) == null)
     {
         Session["modelSaved"] = new List<OrderedItem>();
     }
     if (Request.IsAjaxRequest())
     {
         if ((Session["orderedItems"] as List<OrderedItem>).Count > 0)
         {
             var modelSaved = new OrderedItem();
             foreach (var item in (Session["orderedItems"] as List<OrderedItem>))
             {
                 item.Order.DateReceived = DateTime.Now;
                 item.Order.AmountPaid = item.Quantity * item.MenuItem.Price;
                 modelSaved = _repository.InsertOrderedItem(item);
                 (Session["modelSaved"] as List<OrderedItem>).Add(modelSaved);
             }
             modelSaved = null;
         }
         else
         {
             Session["orderedItems"] = new List<OrderedItem>();
         }
     }
     var menuItemToDelete = Url.Action("Index", "Summary");
     return Json(menuItemToDelete);
 }
        public JsonResult OrderMenuItem(OrderedItem model)
        {
            if ((Session["orders"] as List<Order>) == null)
            {
                Session["orders"] = new List<Order>();
            }
            if ((Session["orderedItems"] as List<OrderedItem>) == null)
            {
                Session["orderedItems"] = new List<OrderedItem>();
            }
            if (Request.IsAjaxRequest())
            {
                var order = new Order();
                //order.OrderId = _repository.GetOrders().Count + 1;
                order.Name = "Order Number: " + _repository.GetOrders().Count;
                order.DateOrdered = DateTime.Now;
                //order.OrderId = _repository.GetOrders().Count + 1;
                order.Customer = Session["customer"] as Customer;
                order.OrderedItems = new List<OrderedItem>();
                order = _repository.InsertOrder(order);
                (Session["orders"] as List<Order>).Add(order);

                var orderItem = new OrderedItem();
                //orderItem.OrderedItemId = _repository.GetOrderedItems().Count + 1;
                orderItem.MenuItem = _repository.GetMenuItemById(model.MenuItemId);
                orderItem.Order = order;
                orderItem.Quantity = model.Quantity;
                orderItem = _repository.InsertOrderedItem(orderItem);
                (Session["orderedItems"] as List<OrderedItem>).Add(orderItem);
            }
            var totalCost = 0.00;
            if ((Session["orders"] as List<Order>).Count > 0)
            {
                foreach (var item in (Session["orderedItems"] as List<OrderedItem>))
                {
                    var quantityAndPrice = 0.00;
                    if (item.Quantity > 0)
                    {
                        quantityAndPrice = item.MenuItem.Price * item.Quantity;
                    }
                    if (quantityAndPrice > 0)
                    {
                        totalCost = totalCost + quantityAndPrice;
                    }
                    else
                    {
                        totalCost = totalCost + item.MenuItem.Price;
                    }
                }
                Session["totalCost"] = totalCost;
            }
            else
            {
                Session["totalCost"] = totalCost;
            }
            //var orderToSave = order;
            var menuItemToSave = new { Url = "Home/Index" };
            //return Json(data);
            return Json(menuItemToSave);
        }
 public OrderedItem UpdateOrderedItem(OrderedItem orderedItem)
 {
     try
     {
         var OrderedItemUpdate = _dBContext.OrderedItems.FirstOrDefault(aOrderedItem => aOrderedItem.OrderedItemId == aOrderedItem.OrderedItemId);
         OrderedItemUpdate.OrderedItemId = orderedItem.OrderedItemId;
         OrderedItemUpdate.Quantity = orderedItem.Quantity;
         OrderedItemUpdate.OrderId = orderedItem.OrderId;
         _dBContext.SaveChanges();
         return orderedItem;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public OrderedItem InsertOrderedItem(OrderedItem orderedItem)
 {
     try
     {
         _dBContext.OrderedItems.Add(orderedItem);
         _dBContext.SaveChanges();
         return orderedItem;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public HttpResponseMessage PutOrderedItem(OrderedItem orderedItem)
 {
     try
     {
         var OrderedItemUpdate = _repository.UpdateOrderedItem(orderedItem);
         return Request.CreateResponse<OrderedItem>(HttpStatusCode.OK, OrderedItemUpdate);
     }
     catch (Exception ex)
     {
         return Request.CreateResponse(HttpStatusCode.NotModified, ex);
     }
 }
 public void InsertOrderedItem(OrderedItem OrderedItem)
 {
     try
     {
         _dBContext.OrderedItems.Add(OrderedItem);
         _dBContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }