public void ProcessRequest(int id) { StockRequest toRemove = null; foreach (var request in list) // interate stockRequests { if (request.Id == id && request.GetAvailability() == true) { // found correct stock request var il = inventory.GetInventoryList(); foreach (var item in il) { if (item.Name.Equals(request.Product)) { toRemove = request; // update store qty UpdateStore(request); // decrement owner qty UpdateOwner(request); } } } } list.Remove(toRemove); WriteStockRequest(); //return false; }
// 0 returned if no match found public int GetCurrentStock() { JsonReader jsr = new JsonReader(); InventoryList il = (InventoryList)jsr.ReadInventoryFile("JSON\\owner_inventory.json"); List <InventoryItem> list = il.GetInventoryList(); foreach (var item in list) { if (item.Id == this.Id) { return(item.StockLevel); } } return(0); }
public void UpdateStore(StockRequest request) { Console.WriteLine("Update store: " + request.Store + " by " + request.Quantity); // open file string filename = "JSON\\" + request.Store + "_Franchise_Inventory.json"; InventoryList StoreInventory = (InventoryList)jsr.ReadInventoryFile(filename); List <InventoryItem> list = StoreInventory.GetInventoryList(); // update foreach (var item in list) { if (item.Name.Equals(request.Product)) { Console.WriteLine("update: " + item.Id + " " + item.Name + " " + request.Quantity); item.ReStock(request.Quantity); } } // write WriteInventory(list, filename); }
public void UpdateOwner(StockRequest request) { Console.WriteLine("update owner: product " + request.Product + " qty " + request.Quantity); // open file string filename = "JSON\\owner_inventory.json"; InventoryList StoreInventory = (InventoryList)jsr.ReadInventoryFile(filename); List <InventoryItem> list = StoreInventory.GetInventoryList(); // update foreach (var item in list) { if (item.Name.Equals(request.Product)) { Console.WriteLine("update: " + item.Id + " " + item.Name + " " + item.StockLevel + " " + request.Quantity); item.StockLevel = item.StockLevel - request.Quantity; } } // write WriteInventory(list, filename); }