public static int GetLocation(IProject0Repo p0Repo, string prompt, int customerId) { ILogger logger = LogManager.GetCurrentClassLogger(); ConsoleDisplay.LocationList(p0Repo); Console.WriteLine(); Console.WriteLine(prompt); var input = Console.ReadLine(); if (input == "d" && customerId != -1) { return(p0Repo.GetDefaultLocation(customerId)); } else if (int.TryParse(input, out var locationId)) { return(locationId); } else { logger.Error($"Invalid input {input}"); return(-1); } }
/// <remarks> /// The following command is the command in Package Manager Console to scaffold and re-scaffold the /// database. I have had to do this 4-5 times already, so I have the command at the top of the /// program so I can grab it. /// </remarks> // Scaffold-DbContext "<your-connection-string>" // Microsoft.EntityFrameworkCore.SqlServer // -Project <name-of-data-project> /// <remarks> /// The following line of code is commented out so that the SQL logging does not interfere with /// using the console. Once the console UI is replaced with a website, I plan on turning /// the SQL logging to the console back on since there will no longer be a conflict. /// </remarks> /// <param name="args"></param> //public static readonly LoggerFactory AppLoggerFactory // = new LoggerFactory(new[] { new ConsoleLoggerProvider((_, __) => true, true) }); static void Main(string[] args) { NLog.ILogger logger = LogManager.GetCurrentClassLogger(); var optionsBuilder = new DbContextOptionsBuilder <Project0Context>(); optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString); //optionsBuilder.UseLoggerFactory(AppLoggerFactory); var options = optionsBuilder.Options; using (var dbContext = new Project0Context(options)) { IProject0Repo p0Repo = new Project0Repo(dbContext); Console.WriteLine("Welcome to Matt's Cupcakes Manager"); Console.WriteLine(); Console.WriteLine("Please select from the following options (not case-sensitive):"); while (true) { ConsoleDisplay.DisplayMenu(); ConsoleRead.GetMenuInput(out var input); if (input == "L") { GetDataAndAddLocation(p0Repo); } else if (input == "C") { GetDataAndAddCustomer(p0Repo); } else if (input == "O") { GetDataAndAddOrder(p0Repo); } else if (input == "LL") { ConsoleDisplay.LocationList(p0Repo); } else if (input == "LO") { ConsoleRead.LocationOrders(p0Repo); } else if (input == "CL") { ConsoleDisplay.CustomerList(p0Repo); } else if (input == "CS") { ConsoleRead.CustomerSearch(p0Repo); } else if (input == "CO") { ConsoleRead.CustomerOrders(p0Repo); } else if (input == "OD") { ConsoleRead.OrderDetails(p0Repo); } else if (input == "OL") { ConsoleDisplay.OrderList(p0Repo, p0Repo.GetAllOrders().ToList(), p0Repo.GetAllOrderItems().ToList(), p0Repo.GetAllCupcakes().ToList(), p0Repo.GetAllLocations().ToList()); } else if (input == "OR") { ConsoleRead.OrderRecommended(p0Repo); } else if (input == "Q") { break; } } } }