示例#1
0
 public ActionResult CreateOrder(OrderModel model)
 {
     if (ModelState.IsValid)
     {
         int recordsCreated = OrderProcessor.CreateOrder
                              (
             model.OrderID,
             model.Date
                              );
         return(RedirectToAction("ViewOrders"));
     }
     return(View());
 }
        public int newOrderCSV(Order order)
        {
            int created = 0;
            int result  = 0;

            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
                        // result = ScheduleController.scheduleOrder(order);
                        if (created == 1)
                        {
                            TempData["newOrderResult"] = "New order is added";
                        }

                        else if (created == -1)
                        {
                            //rollback and remove order
                            OrderProcessor.DeleteOrder(order.orderId);
                            TempData["newOrderResult"] = "Manufacturing Time Data does not exist for this part.Enter part / line data in Line page or change part.";
                        }
                        else if (created == 0)
                        {
                            TempData["newOrderResult"] = "unknown error has occurred during scheduling , please contact administrator.";
                        }
                    }



                    //return result;
                    return(created);
                }
                catch (Exception ex)
                {
                    //  TempData["newOrderResult"] = created;
                    //return RedirectToAction("ViewOrders");
                    return(0);
                }
            }



            TempData["newOrderResult"] = ModelState.Values;



            return(-1);
        }
        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));
        }