Beispiel #1
0
        public ActionResult ProcessOrder(int itemRecommendedProductId, int userRecommendedProductId, int orderId)
        {
            var model = new ChooseProductViewModel();

            model.Order    = db.Orders.ToList().Single(x => x.OrderId == orderId);
            model.Products = db.Products.Where(x => x.IsInStore).ToList();
            model.ItemRecommendedProduct = db.Products.ToList().Single(x => x.ProductId == itemRecommendedProductId);
            model.UserRecommendedProduct = db.Products.ToList().Single(x => x.ProductId == userRecommendedProductId);

            return(View("ChooseProduct", model));
        }
        public ActionResult ChooseProduct()
        {
            // Initialize viewModel object
            var viewModel = new ChooseProductViewModel()
            {
                SelectedProductID = 0,
                Quantity          = 1,
                Products          = _context.Materials.Where(m => m.MaterialTypeID == MaterialType.FinishedProduct).ToList()
            };

            return(View("ChooseProduct", viewModel));
        }
        public ActionResult New(ChooseProductViewModel cpViewModel)
        {
            // Inistialize WO items
            List <WO_Item> woItems = new List <WO_Item>();



            // Get BOM based on selected product id
            var bomHeader = _context.BOM_Headers.Include(b => b.BOM_Items).Where(i => i.ProductID == cpViewModel.SelectedProductID).SingleOrDefault();

            // BOM does not exist
            if (bomHeader == null)
            {
                return(View("BOMIsNonExistent"));
            }

            // Based on bom item list, initialize wo items

            //foreach (var item in bomHeader.BOM_Items)
            foreach (var item in bomHeader.BOM_Items)
            {
                WO_Item woItem = new WO_Item();
                woItem.MaterialID = item.MaterialID;
                woItem.Quantity   = item.Quantity * cpViewModel.Quantity;
                // FIXME Did NOT SET IN WORK ORDER FORM
                woItem.StatusID = Status.NotStart;
                woItems.Add(woItem);
            }

            // Inistialize WO Header
            WO_Header woHeader = new WO_Header();

            woHeader.ProductID = cpViewModel.SelectedProductID;
            woHeader.Quantity  = cpViewModel.Quantity;
            woHeader.DueDate   = DateTime.Now.AddDays(20);
            woHeader.StatusID  = Status.NotStart;

            woHeader.Product = _context.Materials.Find(woHeader.ProductID);

            // Initialize viewModel object
            var viewModel = new WorkOrderViewModel()
            {
                WO_Header    = woHeader,
                WO_Items     = woItems,
                Status       = _context.Status.ToList(),
                Products     = _context.Materials.Where(m => m.MaterialTypeID == MaterialType.FinishedProduct).ToList(),
                RawMaterials = _context.Materials.Where(m => m.MaterialTypeID == MaterialType.RawMaterial).ToList()
            };


            return(View("WorkOrderForm", viewModel));
        }