// GET: Store Index - shows inventory for the user's store. public async Task <IActionResult> Index(string productName, int threshold, int id = 1) { FetchStore(); int storeID = Store.StoreID; Franchisee franchisee = new Franchisee(_context, UserID, storeID); List <StoreInventory> inventory = await franchisee.GetStoreInventory(); // Eager loading the Product table - join between StoreInventory and the Product table. var productQuery = _context.StoreInventory.Include(x => x.Product).Where(p => p.StoreID == storeID); if (!string.IsNullOrWhiteSpace(productName)) { inventory = await franchisee.GetStoreInventory(productName); // Storing the search into ViewBag to populate the textbox with the same value for convenience. ViewBag.ProductName = productName; } if (threshold != 0) { inventory = await franchisee.GetStoreInventoryBelowThreshold(threshold); // Storing the search into ViewBag to populate the textbox with the same value for convenience. ViewBag.Threshold = threshold; } //Passing a List<OwnerInventory> model object to the View. return(View(inventory)); }
// GET: Unstocked Items - show items in Owner Inventory which Store does not have in stock. public async Task <IActionResult> Unstocked() { FetchStore(); int storeID = Store.StoreID; Franchisee franchisee = new Franchisee(_context, UserID, storeID); // Load products in OwnerInventory that aren't in this Store's Inventory var storeInventory = await franchisee.GetStoreInventory(); List <OwnerInventory> inventory = await _context.OwnerInventory.Include(i => i.Product).Where(o => !storeInventory.Any(s => s.ProductID == o.ProductID)).ToListAsync(); //Passing a List<OwnerInventory> model object to the View. return(View(inventory)); }