public ActionResult editOrderCSV(int id)
        {
            var orderData = OrderProcessor.LoadOrder(id);

            Order order = new Order();

            foreach (var row in orderData)
            {
                order.orderId          = row.orderId;
                order.partId           = row.partId;
                order.projectName      = row.projectName;
                order.lastMaterialDate = row.lastMaterialDate;
                order.shipDate         = row.shipDate;
                order.quantity         = row.quantity;
                order.status           = row.status;
                order.priority         = row.priority;
            }

            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.order = order;
            //   OrderPartViewModel.selectedPart = order.partId;
            //   OrderPartViewModel.selectedStatus = order.status;
            //  OrderPartViewModel.selectedPriority = order.priority;

            OrderPartViewModel.parts = parts;



            return(View(OrderPartViewModel));
        }
        public ActionResult newOrder()
        {
            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));
        }
示例#3
0
 private Task BuildViewModel(OrderPartViewModel model, OrderPart part)
 => Task.Run(async() =>
 {
     model.ContentItem = part.ContentItem;
     IDictionary <string, ProductPart> products =
         await _productService.GetProductDictionary(part.LineItems.Select(line => line.ProductSku));
     OrderLineItemViewModel[] lineItems = await Task.WhenAll(part.LineItems.Select(async lineItem =>
     {
         ProductPart product          = products[lineItem.ProductSku];
         ContentItemMetadata metaData = await _contentManager.GetContentItemMetadataAsync(product);
         return(new OrderLineItemViewModel
         {
             Quantity = lineItem.Quantity,
             ProductSku = lineItem.ProductSku,
             ProductName = product.ContentItem.DisplayText,
             UnitPrice = lineItem.UnitPrice,
             LinePrice = lineItem.LinePrice,
             ProductRouteValues = metaData.DisplayRouteValues,
             Attributes = lineItem.Attributes.ToDictionary(attr => attr.Key, attr => attr.Value)
         });
     }));
     model.LineItems = lineItems;
     model.OrderPart = part;
 });
        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));
        }
        public ActionResult editOrderCSV(Order order)
        {
            //  order.partId = selectedPart;
            //  order.status = selectedStatus;
            //   order.priority = selectedPriority;

            int updated = 0;



            if (ModelState.IsValid)
            {
                try
                {
                    updated = OrderProcessor.updateOrder(order.orderId, order.partId, order.projectName, order.lastMaterialDate, order.shipDate, order.quantity, order.status, order.priority);



                    //TempData["newOrderResult"] = created;


                    if (updated == 1)
                    {
                        TempData["newOrderResult"] = 3;
                    }
                    else if (updated == 0)
                    {
                        TempData["newOrderResult"] = 0;
                    }



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

                    return(RedirectToAction("reviewOrderCSVPost"));
                }
            }



            OrderPartViewModel OPViewModel = new OrderPartViewModel();

            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
                });
            }

            OPViewModel.order = order;

            OPViewModel.parts = parts;

            //  OPViewModel.selectedPart = selectedPart;
            // OPViewModel.selectedStatus = selectedStatus;
            // OPViewModel.selectedPriority = selectedPriority;

            return(View(OPViewModel));
        }