///<summary> ///Method that returns a location based on user input ///The location is validated by taking valid locations via data handler classes and asking the user to choose among them /// </summary> private Location EnterLocationDetails() { Console.WriteLine("Choose Branch:"); LocationHandler lh = new LocationHandler(); List <Location> local = lh.GetLocations(); int i = 0; foreach (Location l in local) { Console.WriteLine("[" + i + "] " + l.BranchName); i++; } string choice = Console.ReadLine(); try { return(local[int.Parse(choice)]); } catch (FormatException ex) { Console.WriteLine(ex.Message); ErrorHandler err = new ErrorHandler(); err.InvalidInputMsg(); Log.Error(ex.Message); EnterLocationDetails(); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.Message); Log.Error(ex.Message); EnterLocationDetails(); } return(new Location()); }
///<summary>Method to View Inventory of Chosen Location by passing business logic location object to data handler</summary> private void ViewLocationInventory() { LocationHandler lh = new LocationHandler(); List <Location> locations = lh.GetLocations(); int i = 0; foreach (Location l in locations) { Console.WriteLine($" [{i}] {l.BranchName}"); i++; } string input; do { Console.WriteLine("Choose Branch"); input = Console.ReadLine(); } while (ErrorHandler.InvalidIntInput(input)); try { List <Inventory> storeInventory = lh.GetInventory(locations[int.Parse(input)]); foreach (Inventory inv in storeInventory) { Console.WriteLine("Product: " + inv.Prod.Name + " \n Stock: " + inv.Stock); } Log.Information($"Viewed inventory of {locations[int.Parse(input)].BranchName}"); Menu(); } catch (IndexOutOfRangeException ex) { Console.WriteLine(ex.Message); Log.Error(ex.Message); ViewLocationInventory(); } }