コード例 #1
0
        //public IEnumerable<Assembly> AssemblyList { get; set; }
        public IActionResult OnGet(int?id)
        {
            InventoryItemVM = new InventoryItemVM()
            {
                PurchaseOrderInfo = _unitOfWork.PurchaseOrders.GetAll().ToList(),
                ItemList          = _unitOfWork.InventoryItems.GetItemListForDropDown().OrderBy(i => i.Text),
                MeasureInfo       = _unitOfWork.Measures.GetMeasureListForDropDown(),
                BuildInfo         = new BuildAssembly(),
                AssemblyInfo      = new Assembly(),
                InventoryItemObj  = new InventoryItem()
            };

            BuildAssemblyVM = new BuildAssemblyVM
            {
                InventoryItems  = _unitOfWork.InventoryItems.GetAll(i => i.IsActive == true),
                BuildAssemblies = _unitOfWork.BuildAssemblies.GetAll().Where(i => i.InventoryItemID == id),
                InventoryItem   = _unitOfWork.InventoryItems.GetFirstOrDefault(i => i.InventoryItemID == id),
                Assemblies      = _unitOfWork.Assemblies.GetAll()
            };

            //BuildAssemblyVM.Assemblies.App

            if (id != null)
            {
                InventoryItemVM.InventoryItemObj = _unitOfWork.InventoryItems.GetFirstOrDefault(u => u.InventoryItemID == id);
                if (InventoryItemVM.InventoryItemObj == null)
                {
                    return(NotFound());
                }
                InventoryItemVM.InventoryItemObj.BuildAssemblyList = _unitOfWork.BuildAssemblies.GetAll().Where(b => b.InventoryItemID == id).ToList();
            }
            return(Page());
        }
コード例 #2
0
        public IActionResult Get()
        {
            // used for general information without needing to query the DB again
            buildAssemblyVM = new BuildAssemblyVM()
            {
                InventoryItems  = _unitOfWork.InventoryItems.GetAll().Where(i => i.IsActive == true),
                BuildAssemblies = _unitOfWork.BuildAssemblies.GetAll(),
                Assemblies      = _unitOfWork.Assemblies.GetAll()
            };

            // Initialize the drill's list of items and number required for the drill
            // start with items with 0 required
            List <InventoryItem> tempList = _unitOfWork.InventoryItems.GetAll().Where(i => i.IsAssembly != true && i.IsActive == true).ToList();

            foreach (var item in tempList)
            {
                itemList.Add(new ItemWithCounts()
                {
                    id           = item.InventoryItemID,
                    name         = item.Name,
                    looseQty     = item.TotalLooseQty,
                    requiredQty  = 0,
                    assembledQty = 0,
                    ratio        = 0
                });
            }

            CountAssemblyComponents(drillID, 1); // this is counting the items required for the drill per its recipe
            checkedAssembly.Clear();

            foreach (var item in buildAssemblyVM.InventoryItems)
            {
                // skip the drill -- we don't want to factor it into the item counts
                if (item.IsAssembly && item.InventoryItemID != drillID)
                {
                    CountChildItems(item.InventoryItemID, item.TotalLooseQty); // counting each assembly and item
                }
            }

            // remove items not needed for the drill
            List <int> itemsToRemove = new List <int>();

            foreach (var item in itemList)
            {
                if (item.requiredQty <= 0)
                {
                    itemsToRemove.Add(itemList.IndexOf(item));
                }
            }

            for (int i = itemsToRemove.Count - 1; i > -1; i--)
            {
                itemList.RemoveAt(itemsToRemove[i]);
            }

            // calculate ratio for drill
            foreach (var item in itemList)
            {
                if (item.requiredQty > 0)
                {
                    item.ratio = (item.looseQty + item.assembledQty) / item.requiredQty; // this will still give negatives if the total count is negative
                }
            }

            string json = JsonConvert.SerializeObject(itemList);

            return(Content(json));
        }