static void SeedData() { RepositoryOrder repositoryOrder = new RepositoryOrder(DbContextSingleton.Instance.Context); Order order = new Order(); order.Customer.Name = "jeff"; order.Store = new NewYorkStore(); order.Pizza.Add(new MeatPizza()); order.Pizza.Add(new HawaiianPizza()); repositoryOrder.Add(order); }
/// <summary> /// Prints out a welcome message and the menu. /// Then creates a customer item, allows the user to select a store and pizza. /// The order is then saved to a file/db /// </summary> private static void Run() { var order = new Order(); order.Customer = new Customer(); WelcomeUser(); Console.WriteLine("\nAre you a..."); Console.WriteLine("1 - Customer"); Console.WriteLine("2 - Store Manager"); int tempInput; int options; do { tempInput = SafeUserInput(); } while (tempInput <= 0 || tempInput > 2); if (tempInput == 1) { Console.WriteLine("\nEnter your name:"); order.Customer.Name = Console.ReadLine(); order.Store = SelectStore(); order.Pizza.Add(SelectPizza()); do { DisplayOrder(order); do { options = 0; Console.WriteLine("Do you want to..."); Console.WriteLine($"{++options} - Add another pizza to your order"); Console.WriteLine($"{++options} - Remove a pizza from your order"); Console.WriteLine($"{++options} - Finalize your order"); tempInput = SafeUserInput(); } while (tempInput <= 0 || tempInput > options); switch (tempInput) { case 1: order.Pizza.Add(SelectPizza()); break; case 2: RemovePizza(order); break; case 3: break; default: Console.WriteLine("Something went wrong"); break; } } while (tempInput != options); using (var tempContext = new PizzaDbContext()) { RepositoryOrder repositoryOrder = new RepositoryOrder(DbContextSingleton.Instance.Context); repositoryOrder.Add(order); } order.Save(); } else { var store = SelectStore(); do { options = 0; Console.WriteLine("Do you want to..."); Console.WriteLine($"{++options} - View order history"); Console.WriteLine($"{++options} - View order history for a specific customer"); Console.WriteLine($"{++options} - View the sales report"); tempInput = SafeUserInput(); } while (tempInput <= 0 || tempInput > options); using (var tempContext = new PizzaDbContext()) { RepositoryOrder repositoryOrder = new RepositoryOrder(DbContextSingleton.Instance.Context); List <Order> orders = repositoryOrder.GetList(); int index = 0; string customerName = ""; decimal revenue = 0; if (tempInput == 2) { customerName = Console.ReadLine(); } StringBuilder buffer = new StringBuilder(); foreach (var item in orders) { if (item.Store.Name == store.Name) { switch (tempInput) { case 1: buffer.AppendLine($"\n{++index}:\n{item}"); buffer.AppendLine($"Customer name: {item.Customer.Name}\n"); break; case 2: if (item.Customer.Name.Equals(customerName)) { buffer.AppendLine($"{++index}:\n{item}"); buffer.AppendLine($"Customer name: {item.Customer.Name}\n"); } break; case 3: buffer.AppendLine($"\n{++index}:\n{item}"); buffer.AppendLine($"Customer name: {item.Customer.Name}\n"); revenue += item.priceTotal; break; default: Console.WriteLine("Something went wrong"); break; } } } Console.WriteLine(buffer.ToString()); if (tempInput == 3) { Console.WriteLine($"Total revenue: ${revenue}"); } } } }