public static void LocationOrders(IProject0Repo p0Repo) { ILogger logger = LogManager.GetCurrentClassLogger(); // Get location int locationId = GetLocation(p0Repo, "Please enter the store location Id to get that location's orders:", -1); if (locationId == -1) { return; } if (!p0Repo.CheckLocationExists(locationId)) { logger.Error("This location is not in the system."); return; } // Get all cupcakes var cupcakes = p0Repo.GetAllCupcakes().ToList(); // Get specific location orders var locationOrderHistory = p0Repo.GetLocationOrderHistory(locationId).ToList(); // Get all order items var orderItems = p0Repo.GetAllOrderItems().ToList(); Console.WriteLine($"Store Location {locationId}"); Console.WriteLine(); // Send all information to OrderList to display the orders ConsoleDisplay.OrderList(p0Repo, locationOrderHistory, orderItems, cupcakes, null); }
public static void OrderDetails(IProject0Repo p0Repo) { ILogger logger = LogManager.GetCurrentClassLogger(); Console.WriteLine("Please enter an order Id:"); var input = Console.ReadLine(); if (int.TryParse(input, out var orderId)) { if (!p0Repo.CheckOrderExists(orderId)) { logger.Error("That order is not in the system."); } else { ConsoleDisplay.DisplayOrder(p0Repo.GetCupcakeOrder(orderId), p0Repo.GetOrderItems(orderId).ToList(), p0Repo.GetAllCupcakes().ToList()); } } else { logger.Error($"Invalid input {input}"); } }
public static Dictionary <int, int> GetCupcakes(IProject0Repo p0Repo) { ILogger logger = LogManager.GetCurrentClassLogger(); List <Library.Cupcake> cupcakes = p0Repo.GetAllCupcakes().ToList(); string input; Dictionary <int, int> cupcakeInputs = new Dictionary <int, int>(); while (true) { ConsoleDisplay.CupcakeList(cupcakes); Console.WriteLine("Please enter the number of a cupcake that you would like to order\n" + "or 'C' to continue:"); GetMenuInput(out input); if (input == "C") { break; } else { if (int.TryParse(input, out var cupcakeId)) { if (!p0Repo.CheckCupcakeExists(cupcakeId)) { logger.Error($"{cupcakeId} is not in the list of cupcakes."); cupcakeInputs.Clear(); return(cupcakeInputs); } if (cupcakeInputs.ContainsKey(cupcakeId)) { logger.Error("You have already selected that cupcake in this order."); Console.WriteLine(); } else { cupcakeInputs[cupcakeId] = GetCupcakeQuantity(); if (cupcakeInputs[cupcakeId] == -1) { cupcakeInputs.Clear(); return(cupcakeInputs); } // Remove cupcake from the temporary list of cupcakes // to deter the user from re-entering it. If they re-enter it anyway // they will get an error. cupcakes.Remove(cupcakes.Single(c => c.Id == cupcakeId)); } } else { logger.Error($"Invalid input {input}"); cupcakeInputs.Clear(); return(cupcakeInputs); } } } return(cupcakeInputs); }
public static int GetCustomer(IProject0Repo p0Repo) { ILogger logger = LogManager.GetCurrentClassLogger(); ConsoleDisplay.CustomerList(p0Repo); Console.WriteLine(); Console.WriteLine("Please enter a valid customer Id for the order:"); var input = Console.ReadLine(); if (int.TryParse(input, out var customerId)) { return(customerId); } else { logger.Error($"Invalid input {input}"); return(-1); } }
public static void CustomerOrders(IProject0Repo p0Repo) { ILogger logger = LogManager.GetCurrentClassLogger(); // Get all customers var customers = p0Repo.GetAllCustomers().ToList(); ConsoleDisplay.CustomerList(p0Repo); Console.WriteLine(); Console.WriteLine("Please enter the customer Id to get that customer's orders:"); var input = Console.ReadLine(); if (int.TryParse(input, out var customerId)) { if (!p0Repo.CheckCustomerExists(customerId)) { logger.Error($"Customer {customerId} is not in the list of customers."); return; } foreach (var item in customers.Where(c => c.Id == customerId)) { Console.WriteLine($"Customer {item.FirstName} {item.LastName}"); Console.WriteLine(); // Get specific customer's orders var customerOrderHistory = p0Repo.GetCustomerOrderHistory(customerId).ToList(); // Get all cupcakes var cupcakes = p0Repo.GetAllCupcakes().ToList(); // Get all order items var orderItems = p0Repo.GetAllOrderItems().ToList(); // Send information to OrderList to be displayed ConsoleDisplay.OrderList(p0Repo, customerOrderHistory, orderItems, cupcakes, null); } } else { logger.Error($"Invalid input {input}"); } }
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); } }
static void Main(string[] args) { ILogger logger = LogManager.GetCurrentClassLogger(); string jsonLocations = @"C:\revature\luigi_cupcakes_locations.json"; string jsonCustomers = @"C:\revature\luigi_cupcakes_customers.json"; string jsonOrders = @"C:\revature\luigi_cupcakes_orders.json"; LoadDataFromJSON(jsonLocations, jsonCustomers, jsonOrders, out var storeLocations, out var customers, out var orders); Console.WriteLine("Welcome to Luigi'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 == "S") { GetDataAndAddLocation(jsonLocations, storeLocations); } else if (input == "C") { GetDataAndAddCustomer(jsonCustomers, customers, storeLocations); } else if (input == "O") { GetDataAndAddOrder(jsonLocations, jsonCustomers, jsonOrders, customers, storeLocations, orders); } else if (input == "SL") { ConsoleDisplay.StoreList(storeLocations); } else if (input == "SO") { ConsoleRead.StoreOrders(storeLocations); } else if (input == "CL") { ConsoleDisplay.CustomerList(customers); } else if (input == "CS") { ConsoleRead.CustomerSearch(customers); } else if (input == "CO") { ConsoleRead.CustomerOrders(customers); } else if (input == "OL") { ConsoleDisplay.OrderList(orders, storeLocations); } else if (input == "OR") { ConsoleRead.OrderRecommended(customers, orders); } else if (input == "Q") { break; } } }
/// <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; } } } }