//
        // /Inventory/ConcludeInventory
        public ActionResult ConcludeInventory()
        {
            InventoryContext db = new InventoryContext();
            var inventories = db.Inventories.Select(x => x).ToList();
            var inv = inventories.LastOrDefault();
            inv.Completed = true;

            foreach (var item in db.InventoryItems.Where(x => x.InventoryId == inv.Id)) {
                item.IsInventoried = false;
            }

            db.Entry(inv).State = EntityState.Modified;
            db.SaveChanges();

            //TODO: Create Confirmation Page
            return RedirectToAction("Index");
        }
        public ActionResult TakeItemInventory(TestItemInventoryVM vm)
        {
            InventoryContext db = new InventoryContext();
            Inventory inventory = db.Inventories.Find(vm.InventoryId);

            foreach (var item in vm.RegularlyOrderedProducts) {
                Product product = db.Products.Find(item.Id);
                var retrievedInvItem = (from i in db.InventoryItems
                                    where i.ProductId == product.Id && i.InventoryId == inventory.Id
                                    select i).FirstOrDefault();
                InventoryItem invItem = new InventoryItem {
                    Product = product,
                    ProductId = product.Id,
                    Inventory = inventory,
                    InventoryId = inventory.Id,
                    Quantity = item.UnitsInStock
                };

                //Ensure Quantity has changed before trying to set values
                if (item.UnitsInStock != product.UnitsInStock) {
                    invItem.IsInventoried = true;
                }

                //If the InventoryItem is different from what's passed from the view, always take what's passed from the view
                else if (item.IsInventoried != invItem.IsInventoried) {
                    invItem.IsInventoried = item.IsInventoried;
                }

                //Set UnitsInStock on Product
                product.UnitsInStock = item.UnitsInStock;
                db.Entry(product).State = EntityState.Modified;

                //If record exists, update it.
                if (retrievedInvItem != null) {
                    db.Entry(retrievedInvItem).CurrentValues.SetValues(invItem);
                }

                //If record doesn't exist, add it
                else {
                    db.InventoryItems.Add(invItem);
                }
                db.SaveChanges();
            }
            return RedirectToAction("TakeInventory");
        }