public ActionResult reviewOrderCSVSchedule(int[] orderId, string[] status)
        {
            List <Order> listOrders     = new List <Order>();
            List <Order> tempListOrders = new List <Order>();

            for (int i = 0; i < status.Length; i++)
            {
                //check status , if status = unschedule , dont schedule
                Order order = new Order();
                order = getOrderById(orderId[i]);
                if (status[i].Equals("false"))
                {
                    // dont schedule here

                    order.intTempResult    = -1;
                    order.StringTempResult = "Unscheduled";

                    listOrders.Add(order);
                }
                else
                {
                    tempListOrders.Add(order);
                }
            }

            //sort order by shipping date
            //tempListOrders = tempListOrders.OrderByDescending(o => o.shipDate).ToList();

            //tempListOrders.Sort((x, y) => x.shipDate.CompareTo(y.shipDate));


            tempListOrders = tempListOrders.OrderBy(x => x.lastMaterialDate).ThenBy(x => x.shipDate).ToList();

            for (int i = 0; i < tempListOrders.Count; i++)
            {
                //check status , if status = unschedule , dont schedule
                Order order = tempListOrders[i];



                int scheduled = ScheduleController.scheduleOrder(order);
                //int scheduled = 0;
                if (scheduled == 1)
                {
                    order.intTempResult    = 1;
                    order.StringTempResult = "Scheduled";
                }
                else
                {
                    order.intTempResult    = 0;
                    order.StringTempResult = "An exception has occured, scheduling is aborted.Please try again.";
                }


                listOrders.Add(order);
            }



            TempData["Orders"] = listOrders;

            return(RedirectToAction("scheduledResults"));
        }
        public ActionResult newOrder(Order order, int selectedPart)
        {
            int created = 0;

            order.status   = "unscheduled";
            order.priority = 3;



            order.partId = selectedPart;
            if (ModelState.IsValid)
            {
                try
                {
                    created = OrderProcessor.CreateOrder(
                        order.orderId,
                        order.partId,
                        order.projectName,
                        order.lastMaterialDate,
                        order.shipDate,
                        order.quantity);



                    //TempData["newOrderResult"] = created;


                    if (created == 1)
                    {
                        // Schedule object
                        int result = ScheduleController.scheduleOrder(order);
                        if (result == 1)
                        {
                            TempData["newOrderResult"] = 1;
                        }
                        else if (result == -1)
                        {
                            //rollback and remove order
                            OrderProcessor.DeleteOrder(order.orderId);
                            TempData["newOrderResult"] = -1;
                        }
                        else if (result == 0)
                        {
                            TempData["newOrderResult"] = 0;
                        }
                    }



                    return(RedirectToAction("ViewOrders"));
                }
                catch (Exception ex)
                {
                    //  TempData["newOrderResult"] = created;
                    //return RedirectToAction("ViewOrders");
                    return(View(ex.Message));
                }
            }

            ModelState.AddModelError("", "Error");
            List <Part> parts = new List <Part>();
            var         data  = PartProcessor.LoadPart();

            foreach (var row in data)
            {
                parts.Add(new Part
                {
                    partId   = row.partId,
                    partName = row.partName,
                    side     = row.side
                });
            }



            OrderPartViewModel OrderPartViewModel = new OrderPartViewModel();

            OrderPartViewModel.parts = parts;


            return(View(OrderPartViewModel));
        }