//function to process input form owner private void ProcessRequest() { while (true) { Console.Write("\nEnter request to process: "); var input = Console.ReadLine(); Console.WriteLine(); //if the user give a null input, then no request will be processed and the menu will go back to owner sub menu if (string.IsNullOrEmpty(input)) { break; } //a new input will be requested if user entered a non-number if (!int.TryParse(input, out var id)) { Console.WriteLine("Invalid input."); continue; } //if user entered an id that is not on the current list and new input will be requested var request = OwnerManager.GetRequest(id); if (request == null) { Console.WriteLine("No such request."); continue; } //process the request if availability is true and passed all the conditions above if (request.StockAvailabilty.Equals("True")) { //setup to use the related sql operation later on var ownerItem = OwnerManager.GetItem(request.ProductID); ownerItem.StockLevel -= request.Quantity; OwnerManager.UpdateItemStock(ownerItem); FranchiseHolderManager.StoreID = request.StoreID; FranchiseHolderManager.GetStoreStock(); var holderItem = FranchiseHolderManager.GetItem(request.ProductID); holderItem.StockLevel += request.Quantity; //finish up the request in 3 parts: 1 - update owner stock, 2 - update franchiseholder stock, 3- delete the request from database FranchiseHolderManager.UpdateItemStock(holderItem); OwnerManager.DeleteRequest(request); Console.WriteLine($"Filled request - {request.ProductName} for store - {request.StoreName}.\n"); } else { Console.WriteLine("You do not have enough stock to fulfil the request.\n"); continue; } break; } }
//function to restock item for owner private void ResetStock() { Console.WriteLine("Reset Stock\nProduct stock will be reset to 20.\n"); //if items from inventory cannot be fetched, the operation will not continue in order to prevent crash if (!OwnerManager.Items.Any()) { Console.WriteLine("No items present.\n"); return; } //using the shared function from customutilities class to display the item list CustomUtilities.DisplayItems(OwnerManager.Items); while (true) { Console.Write("Enter item ID to reset: "); var input = Console.ReadLine(); Console.WriteLine(); //if the user give a null input, then no request will be processed and the menu will go back to owner sub menu if (string.IsNullOrEmpty(input)) { break; } //if user entered a non-number a new input will be requested if (!int.TryParse(input, out var id)) { Console.WriteLine("Invalid input.\n"); continue; } //if user entered an id that is not on the current list and new input will be requested var item = OwnerManager.GetItem(id); if (item == null) { Console.WriteLine("No such item.\n"); continue; } //input passed all conditions above and restock function will be called ResetStock(item); break; } }