public static string FinalizeOrder(Location l, Order o, PizzaStoreRepository repo) { Console.WriteLine($"Thank you for your order. Your total is ${o.Price}"); Console.WriteLine("Here are the details of your order:"); for (var i = 0; i < o.PizzaList.Count; i++) { Console.WriteLine($"Pizza {i + 1}:"); Console.WriteLine($"Size: { o.PizzaList[i].PizzaSize}"); Console.WriteLine("Toppings:"); foreach (KeyValuePair <string, bool> entry in o.PizzaList[i].Toppings) { if (entry.Value == true) { Console.WriteLine(entry.Key); } } Console.WriteLine(); Console.WriteLine(); } repo.PrintOrderHistory(o); repo.UpdateOrder(o); repo.Save(); return("Order Finished."); }
public void TestGetLocation() { var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var configuration = configBuilder.Build(); var optionsBuilder = new DbContextOptionsBuilder <PizzaStoreDbContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzastoreDB")); var options = optionsBuilder.Options; var dbContext = new PizzaStoreDbContext(options); var PizzaStoreRepository = new PizzaStoreRepository(dbContext); var actual = PizzaStoreRepository.GetLocationById(3); Assert.Equal(3, actual.StoreNumber); }
public void TestIsUserInDB() { var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var configuration = configBuilder.Build(); var optionsBuilder = new DbContextOptionsBuilder <PizzaStoreDbContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzastoreDB")); var options = optionsBuilder.Options; var dbContext = new PizzaStoreDbContext(options); var PizzaStoreRepository = new PizzaStoreRepository(dbContext); var actual = PizzaStoreRepository.IsUserInDB("joseph", "isble"); Assert.True(actual); }
public void TestAddUserToDBAndGetUserFromDB() { var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var configuration = configBuilder.Build(); var optionsBuilder = new DbContextOptionsBuilder <PizzaStoreDbContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzastoreDB")); var options = optionsBuilder.Options; var dbContext = new PizzaStoreDbContext(options); var PizzaStoreRepository = new PizzaStoreRepository(dbContext); User testuser = new User("Kylo", "Ren", 1); PizzaStoreRepository.AddUserToDB(testuser); PizzaStoreRepository.Save(); Assert.Equal(testuser.First, PizzaStoreRepository.GetUser(testuser.First, testuser.Last).First); }
public ViewModelOrderPizzaController(PizzaStoreRepository repo, PizzaStoreDBContext context) { Repo = repo; _context = context; }
public static void AddTopping(Location l, Pizza p, string topping, string ans, PizzaStoreRepository repo) { if (ans == "y") { if (l.Inventory[topping] > 0) { //p.Toppings.Add(topping); //$1 toppings p.Price++; l.Inventory[topping]--; p.Toppings[topping] = true; repo.UpdateInventory(l); repo.Save(); Console.WriteLine($"Current toppings for the {p.PizzaSize} pizza is: "); foreach (KeyValuePair <string, bool> entry in p.Toppings) { if (entry.Value == true) { Console.WriteLine(entry.Key); } } } else { Console.WriteLine("Sorry, we currently do not have that topping in stock."); Console.WriteLine($"{topping} was NOT added."); } } }
public OrderController(PizzaStoreRepository repo) { Repo = repo; }
public LocationController(PizzaStoreRepository repo) { Repo = repo; }
static void Main(string[] args) { logger.Info("Application start"); var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); var configuration = configBuilder.Build(); var optionsBuilder = new DbContextOptionsBuilder <PizzaStoreDbContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzastoreDB")); var options = optionsBuilder.Options; var dbContext = new PizzaStoreDbContext(options); var PizzaStoreRepository = new PizzaStoreRepository(dbContext); var userSerializer = new XmlSerializer(typeof(List <User>)); var locationSerializer = new XmlSerializer(typeof(List <Location>)); List <User> UserList = new List <User>(); List <Location> LocationList = new List <Location>(); Dictionary <string, User> Users_Dict = new Dictionary <string, User>(); Dictionary <int, Location> Location_Dict = new Dictionary <int, Location>(); try { using (var stream = new FileStream("User_data.xml", FileMode.Open)) { UserList = (List <User>)userSerializer.Deserialize(stream); } } catch (FileNotFoundException) { Console.WriteLine("Saved data not found"); } foreach (var item in UserList) { string firstlast = item.First + item.Last; Users_Dict.Add(firstlast, item); } try { using (var stream = new FileStream("Location_data.xml", FileMode.Open)) { LocationList = (List <Location>)locationSerializer.Deserialize(stream); } } catch (FileNotFoundException) { Console.WriteLine("Saved data not found"); } foreach (var item in LocationList) { int Location = item.StoreNumber; Location_Dict.Add(Location, item); } if (Location_Dict.Count == 0) { Location_Dict.Add(1, new Location(1)); Location_Dict.Add(2, new Location(2)); Location_Dict.Add(3, new Location(3)); Location_Dict.Add(4, new Location(4)); } string whichProgram = ""; Console.WriteLine("Which program would you like to run (DB or XML)"); whichProgram = Console.ReadLine().ToLower(); if (whichProgram == "db") { bool running = true; string FirstName = ""; string LastName = ""; Console.WriteLine("Please enter your Fist Name: "); FirstName = Console.ReadLine().ToLower().Replace(" ", string.Empty); Console.WriteLine("Please enter your Last Name: "); LastName = Console.ReadLine().ToLower().Replace(" ", string.Empty); int userstore; while (!PizzaStoreRepository.IsUserInDB(FirstName, LastName)) { Console.WriteLine("Welcome new user. Please enter your preffered store"); while (true) { Console.WriteLine("Stores are: 1, 2, 3, 4"); Console.WriteLine("Preffered store:"); string input = Console.ReadLine(); userstore = Convert.ToInt32(input); if (PizzaStoreRepository.IsLocationInDB(userstore)) { User newUser = new User(FirstName, LastName, userstore); PizzaStoreRepository.AddUserToDB(newUser); PizzaStoreRepository.Save(); Console.WriteLine("Preferred location has been updated"); break; } else { Console.WriteLine("That is not a valid store ID"); } } } Console.WriteLine($"Welcome {FirstName} {LastName}. Type a command for what you would like to do."); while (running) { User NewUser = PizzaStoreRepository.GetUser(FirstName, LastName); List <Order> OrderHistory = PizzaStoreRepository.GetUserOrderHistory(NewUser); foreach (var item in OrderHistory) { Console.WriteLine(item); } string Input = ""; Console.WriteLine("Commands are: order, history, quit"); Input = Console.ReadLine().ToLower(); switch (Input) { case "order": Console.WriteLine("Would you like your preferred order or a new order? (type \"preferred\" for preferred order, or \"new\" for a new order"); Input = Console.ReadLine().ToLower(); int NumberOfPizza = 0; switch (Input) { case "preferred": if (!PizzaStoreRepository.DoesUserHavePreviousOrders(NewUser)) { Console.WriteLine("You have no previous orders, preferred order is not possible at this time."); break; } Library.PizzaPie newPizza = new Library.PizzaPie(); newPizza.MakePizza(PizzaStoreRepository.GetUserRecentOrder(NewUser).Pizza.Sauce, PizzaStoreRepository.GetUserRecentOrder(NewUser).Pizza.Toppings, PizzaStoreRepository.GetUserRecentOrder(NewUser).Pizza.Size); Order PrefOrder = new Order(PizzaStoreRepository.GetUserRecentOrder(NewUser).HowManyPizzas, PizzaStoreRepository.GetUserRecentOrder(NewUser).Pizza.Toppings, NewUser, NewUser.PrefLocation, PizzaStoreRepository.GetUserRecentOrder(NewUser).Pizza); PrefOrder.AddPizzaToOrder(newPizza); PrefOrder.UpdateToppings(newPizza.Toppings); PrefOrder.UpdatePriceOfOrder(newPizza.Price); PrefOrder.TimepizzaWasOrdered(); int new_user_id = PizzaStoreRepository.GetUserID(NewUser); PrefOrder.UpdateUserId(new_user_id); PizzaStoreRepository.AddOrderToDB(PrefOrder); PizzaStoreRepository.Save(); newPizza.UpdatePizzaOrderID(PizzaStoreRepository.GetUserRecentOrder(NewUser).OrderID); PizzaStoreRepository.AddPizzaToDB(newPizza); PizzaStoreRepository.Save(); Console.WriteLine("Order has been created!"); break; case "new": Console.WriteLine("How many pizzas will you be ordering?"); string input = Console.ReadLine().ToLower(); NumberOfPizza = Convert.ToInt32(input); Dictionary <string, bool> toppings = new Dictionary <string, bool>() { { "pepperoni", false }, { "ham", false }, { "chicken", false }, { "sausage", false }, { "bbqchicken", false }, { "onion", false }, { "pepper", false }, { "pineapple", false } }; HashSet <string> toppingsset = new HashSet <string>(); Library.PizzaPie NewPizza = new Library.PizzaPie(); foreach (var item in toppings.Keys) { toppingsset.Add(item); } try { Order TestOrder = new Order(NumberOfPizza, toppingsset, NewUser, NewUser.PrefLocation, NewPizza); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); break; } Order NewOrder = new Order(NumberOfPizza, toppingsset, NewUser, NewUser.PrefLocation, NewPizza); Console.Write("What size pizza would you like? (S, M, L):"); string pizzaSize = Console.ReadLine().ToLower().Replace(" ", string.Empty); Console.Write("Would you like Sauce? y/n:"); string sauceinput = Console.ReadLine().ToLower().Replace(" ", string.Empty); bool sauce; if (sauceinput == "y") { sauce = true; } else if (sauceinput == "n") { sauce = false; } else { Console.WriteLine("invalid input, please create your order again"); break; } while (true) { Console.WriteLine("Please type the toppings you want one at a time."); Console.WriteLine("Possible toppings include: Pepperoni, Onion, Ham, Sausage, Chicken, Pepper, Pineapple, and BBQChicken"); Console.Write("When you are done adding your toppings type \"done\":"); string topping = Console.ReadLine().ToLower().Replace(" ", string.Empty); if (topping == "done") { break; } else { toppingsset.Add(topping); toppings[topping] = true; } } try { NewPizza.MakePizza(sauce, toppingsset, pizzaSize); } catch (ArgumentException) { Console.WriteLine("Invalid topping was removed from order."); } NewPizza.PricePizza(pizzaSize, toppingsset, NumberOfPizza); if (NewPizza.Price > 500) { Console.WriteLine("Price of pizza is too high, canceling order"); break; } NewPizza.MakePizzaDict(sauce, toppings, pizzaSize); NewOrder.AddPizzaToOrder(NewPizza); NewOrder.UpdateToppings(NewPizza.Toppings); NewOrder.UpdatePriceOfOrder(NewPizza.Price); NewOrder.TimepizzaWasOrdered(); int newuserid = PizzaStoreRepository.GetUserID(NewUser); NewOrder.UpdateUserId(newuserid); PizzaStoreRepository.AddOrderToDB(NewOrder); PizzaStoreRepository.Save(); NewPizza.UpdatePizzaOrderID(PizzaStoreRepository.GetUserRecentOrder(NewUser).OrderID); NewPizza.UpdateToppingDict(toppings); PizzaStoreRepository.AddPizzaToDB(NewPizza); PizzaStoreRepository.Save(); Console.WriteLine("Order has been made"); Console.WriteLine(); break; } break; case "history": List <Order> orderhistory = PizzaStoreRepository.GetUserOrderHistory(NewUser); Console.WriteLine("How would you like to sort your order history?"); Console.WriteLine("cheapest, most expensive, earliest, latest"); string sort = Console.ReadLine().ToLower(); if (sort == "earliest") { foreach (var item in orderhistory) { Console.WriteLine($"Order:{item.OrderID} you ordered:{item.HowManyPizzas} Pizzas From: Store {item.Location} At:{item.TimeOfOrder} and it cost: ${item.Price}"); } } if (sort == "latest") { orderhistory.Reverse(); foreach (var item in orderhistory) { Console.WriteLine($"Order:{item.OrderID} you ordered:{item.HowManyPizzas} From:{item.Location} At:{item.TimeOfOrder} and cost: ${item.Price}"); } } break; case "quit": running = false; break; } } } else { bool running = true; string FirstName = ""; string LastName = ""; Console.WriteLine("Please enter your Fist Name: "); FirstName = Console.ReadLine().ToLower().Replace(" ", string.Empty); Console.WriteLine("Please enter your Last Name: "); LastName = Console.ReadLine().ToLower().Replace(" ", string.Empty); string FirstLast = FirstName + LastName; while (!Users_Dict.ContainsKey(FirstLast)) { Console.WriteLine("Welcome new user. Please enter your preffered store"); while (true) { Console.WriteLine("Stores are: 1, 2, 3, 4"); Console.WriteLine("Preffered store:"); string input = Console.ReadLine(); int loc = Convert.ToInt32(input); if (Location_Dict.ContainsKey(loc)) { User newUser = new User(FirstName, LastName, loc); Users_Dict.Add(FirstLast, newUser); Console.WriteLine("Preferred location has been updated"); break; } else { Console.WriteLine("That is not a valid store ID"); } } } Console.WriteLine($"Welcome {FirstName} {LastName}. Type a command for what you would like to do."); while (running) { int location = Users_Dict[FirstLast].PrefLocation; string Input = ""; Console.WriteLine("Commands are: order, Order history, change location, quit"); Input = Console.ReadLine().ToLower(); switch (Input) { case "order": Console.WriteLine("Would you like your preferred order or a new order? (type \"preferred\" for preferred order, or \"new\" for a new order"); Input = Console.ReadLine().ToLower(); int NumberOfPizza = 0; switch (Input) { case "preferred": if (Users_Dict[FirstLast].OrderHistory.Count < 1) { Console.WriteLine("You have no previous orders, preferred order is not possible at this time."); break; } Library.PizzaPie PrefOrderPizza = new Library.PizzaPie(); string OrderToppings = ""; foreach (var item in Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Toppings) { OrderToppings += item + ", "; } Console.WriteLine($"Your preferred order is size:{Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Size} Sauce: {Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Sauce} Toppings: {OrderToppings} Cost: {Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Price}"); Order PrefOrder = new Order(Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].HowManyPizzas, Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Toppings, Users_Dict[FirstLast], Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Location, PrefOrderPizza); PrefOrderPizza.MakePizza(Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Sauce, Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Toppings, Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Size); PrefOrder.AddPizzaToOrder(PrefOrderPizza); PrefOrder.UpdateToppings(Users_Dict[FirstLast].OrderHistory[Users_Dict[FirstLast].OrderHistory.Count - 1].Pizza.Toppings); PrefOrder.Price = PrefOrderPizza.Price; PrefOrder.TimepizzaWasOrdered(); Location_Dict[location].DecreaseInventory(PrefOrder); Users_Dict[FirstLast].SetOrderHistory(PrefOrder); Console.WriteLine("Order has been created!"); break; case "new": Console.WriteLine("How many pizzas will you be ordering?"); string input = Console.ReadLine().ToLower(); NumberOfPizza = Convert.ToInt32(input); HashSet <string> toppings = new HashSet <string>(); Library.PizzaPie NewPizza = new Library.PizzaPie(); try { Order TestOrder = new Order(NumberOfPizza, toppings, Users_Dict[FirstLast], Location_Dict[Users_Dict[FirstLast].PrefLocation].StoreNumber, NewPizza); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); break; } Order NewOrder = new Order(NumberOfPizza, toppings, Users_Dict[FirstLast], Location_Dict[Users_Dict[FirstLast].PrefLocation].StoreNumber, NewPizza); Console.Write("What size pizza would you like? (S, M, L):"); string pizzaSize = Console.ReadLine().ToLower().Replace(" ", string.Empty); Console.Write("Would you like Sauce? y/n:"); string sauceinput = Console.ReadLine().ToLower().Replace(" ", string.Empty); bool sauce; if (sauceinput == "y") { sauce = true; } else if (sauceinput == "n") { sauce = false; } else { Console.WriteLine("invalid input, please create your order again"); break; } while (true) { Console.WriteLine("Please type the toppings you want one at a time."); Console.WriteLine("Possible toppings include: Pepperoni, Onion, Ham, Sausage, Chicken, Pepper, Pineapple, and BBQChicken"); Console.Write("When you are done adding your toppings type \"done\":"); string topping = Console.ReadLine().ToLower().Replace(" ", string.Empty); if (topping == "done") { break; } toppings.Add(topping); } try { NewPizza.MakePizza(sauce, toppings, pizzaSize); } catch (ArgumentException) { Console.WriteLine("Invalid topping was removed from order."); } NewPizza.PricePizza(pizzaSize, toppings, NumberOfPizza); if (NewPizza.Price > 500) { Console.WriteLine("Price of pizza is too high, canceling order"); break; } NewOrder.AddPizzaToOrder(NewPizza); NewOrder.UpdateToppings(toppings); NewOrder.UpdatePriceOfOrder(NewPizza.Price); NewOrder.TimepizzaWasOrdered(); Location_Dict[location].DecreaseInventory(NewOrder); Users_Dict[FirstLast].SetOrderHistory(NewOrder); Console.WriteLine("Order has been made"); Location_Dict[location].SetOrderHistory(NewOrder); Console.WriteLine(); break; } break; case "change location": while (true) { Console.Write("Please enter the store ID you would like to change to, 1, 2, 3, or 4:"); string input = Console.ReadLine().ToLower().Replace(" ", string.Empty); int IntInput = Convert.ToInt32(input); if (Location_Dict.ContainsKey(IntInput)) { Users_Dict[FirstLast].PrefLocation = IntInput; Console.WriteLine("Preferred location has been updated"); break; } else { Console.WriteLine("That is not a valid store ID"); } } break; case "quit": running = false; List <User> userList = new List <User>(); List <Location> locationList = new List <Location>(); foreach (KeyValuePair <string, User> item in Users_Dict) { userList.Add(item.Value); } foreach (KeyValuePair <int, Location> item in Location_Dict) { locationList.Add(item.Value); } try { using (var stream = new FileStream("User_data.xml", FileMode.Create)) { userSerializer.Serialize(stream, userList); } using (var stream = new FileStream("Location_data.xml", FileMode.Create)) { locationSerializer.Serialize(stream, locationList); } } catch (IOException ex) { Console.WriteLine($"Error during save: {ex.Message}"); } break; } } } }
public MainController(PizzaStoreRepository repo) { Repo = repo; }
public HomeController(PizzaStoreRepository repo) { Repo = repo; }
public UsersController(PizzaStoreRepository repo) { Repo = repo; }
static void Main(string[] args) { var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = configBuilder.Build(); var optionsBuilder = new DbContextOptionsBuilder <PizzaStoreDBContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzaStoreDB")); var options = optionsBuilder.Options; var PizzaStoreDBContext = new Data.PizzaStoreDBContext(options); var PizzaStoreRepo = new PizzaStoreRepository(PizzaStoreDBContext); Console.WriteLine("Welcome to Revature's PizzaStore!"); PizzaStoreRepo.PrintOrderHistory(PizzaStoreRepo.SortByLatest()); Console.WriteLine("To begin, please enter your Name"); Console.Write("First Name: "); string fn = Console.ReadLine(); Console.Write("Last Name: "); string ln = Console.ReadLine(); string name = User.FirstandLastName(fn, ln); //Check if pre-existing user: Console.WriteLine("Here are our locations:"); Console.WriteLine("Location 1 - 123 Alpha street"); Console.WriteLine("Location 2 - 456 Bravo street"); Console.WriteLine("Location 3 - 789 Charlie street"); Console.WriteLine("Location 4 - 246 Delta street"); Console.WriteLine("Location 5 - 135 Echo street"); string answer; while (true) { Console.WriteLine("Please enter your preferred location number"); answer = Console.ReadLine(); if (!int.TryParse(answer, out int n)) { Console.WriteLine("Please enter a number between 1 and 5"); } else if (int.Parse(answer) > 0 && int.Parse(answer) < 6) { break; } else { Console.WriteLine("Not a valid store! Write a number 1 to 5"); } } int PreferredLocation = int.Parse(answer); PizzaStoreRepo.PrintOrderHistory(PizzaStoreRepo.GetOrdersByLocation(PreferredLocation)); string toPrint; //If user exists already: if (PizzaStoreRepo.DoesUserExist(fn, ln)) { User u = PizzaStoreRepo.GetUser(fn, ln); if (u.DefaultLocation != PreferredLocation) { Console.WriteLine($"Your default location is {u.DefaultLocation}. Would you like to change it to {PreferredLocation}? [y/n]"); string ans = Console.ReadLine(); if (ans == "y") { u.DefaultLocation = PreferredLocation; PizzaStoreRepo.UpdateUser(u); PizzaStoreRepo.Save(); //UPDATE THE USER HERE AND SAVE TO REPO } } Console.WriteLine($"Your most recent order is:"); PizzaStoreRepo.PrintOrderHistory(PizzaStoreRepo.GetMostRecentOrderByUser(u)); toPrint = OrderHandler.BeginOrder(name, u, Master.LocationList[PreferredLocation - 1], PizzaStoreRepo); } else { User u = new User(name) { FirstName = fn, LastName = ln, Name = name, DefaultLocation = PreferredLocation }; Master.UserDict.Add(name, u); PizzaStoreRepo.AddUser(u); PizzaStoreRepo.Save(); Console.WriteLine($"the user id is {PizzaStoreRepo.GetUserID(u)}"); Console.WriteLine("Delete this user?"); string answe = Console.ReadLine(); if (answe == "y") { PizzaStoreRepo.DeleteUser(u); PizzaStoreRepo.Save(); return; } toPrint = OrderHandler.BeginOrder(name, u, Master.LocationList[PreferredLocation - 1], PizzaStoreRepo); } Console.WriteLine(toPrint); }
static void Main(string[] args) { #region Database #region Database var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("Appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); Console.WriteLine(configuration.GetConnectionString("PizzaPalace")); #endregion var optionsBuilder = new DbContextOptionsBuilder <PizzaPalaceContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzaPalace")); var repo = new PizzaStoreRepository(new PizzaPalaceContext(optionsBuilder.Options)); #endregion int option = 1; Methods m = new Methods(); #region Menu while (option != 0) { try { m.PrintAll(); option = int.Parse(Console.ReadLine()); //This if will call a method an populate the inventory. if (option == 1) { m.LoadFromDB(); } //This if will contain the order info to pass it to parameters to another class so it can be processed. if (option == 2) { Console.WriteLine("These are the options for your pizza. Choose one: "); m.PrintPizza(); Console.WriteLine(); try { int pizzaOption = int.Parse(Console.ReadLine()); int pizzaQty = 0; int i; int count = 0; if (int.TryParse(pizzaOption.ToString(), out i)) { count++; if (count == 1) { if (pizzaOption >= 0) { try { #region UserInfo Console.WriteLine("Lets place a order but first. Fill the require information about you. "); Console.WriteLine("Enter the First Name: "); string fName = Console.ReadLine(); Console.WriteLine("Enter the Last Name: "); string lName = Console.ReadLine(); m.SearchUser(fName, lName); Console.WriteLine("What is the location of this user? "); m.PrintLocations(); int locationUser = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the user ID you want to use the order with: "); int userID = int.Parse(Console.ReadLine()); m.PrintLocations(); Console.WriteLine("What is the location ID of the store: "); int locationID = int.Parse(Console.ReadLine()); #endregion Console.WriteLine("How many " + m.piz[pizzaOption].NamePizza.ToString() + " Pizza do you want? "); pizzaQty = int.Parse(Console.ReadLine()); if (int.TryParse(pizzaQty.ToString(), out i)) { if (pizzaQty <= int.Parse(m.piz[pizzaOption].CountPizza.ToString())) { // m.OrderPizza(userID, locationID, pizzaOption, pizzaQty); repo.AddOrder(locationID, userID, locationUser, DateTime.Now, pizzaOption, pizzaQty); repo.Save(); } else { Console.WriteLine("We are low on stock at the moment. Please try again later. Thanks."); } } } catch (FormatException ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } } } } } catch (FormatException ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } } if (option == 3) { Console.WriteLine("Enter a user ID to search the suggested pizza: "); m.PrintSuggestedOrder(int.Parse(Console.ReadLine())); // m.getCountOfList(); } if (option == 4) { Console.WriteLine("Enter a Name to display its data: "); var name = Console.ReadLine(); Console.WriteLine("Enter Last Name: "); var lName = Console.ReadLine(); m.SearchUser(name, lName); } if (option == 5) { Console.WriteLine("Enter the order ID you want to display: "); m.DisplayOrderByID(int.Parse(Console.ReadLine())); } if (option == 6) { Console.WriteLine("What is the location of the store you are looking for? "); m.DisplayOrderByLocation(int.Parse(Console.ReadLine())); } if (option == 7) { Console.WriteLine("Enter a ID from user you want to view the order history from: "); m.DisplayOrdersByUser(Console.ReadLine()); } if (option == 8) { m.SortByAll(); } if (option == 9) { m.serializeToXML(); } if (option == 10) { m.DezerializedAsync(); } } catch (FormatException ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error: ", ex); Console.WriteLine(ex); } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } } #endregion }
static void Main(string[] args) { var saveLocation = "../../../../json.txt"; string input; List <PizzaStore> stores; var dataSource = new List <PizzaStore>(); //for initializing repo var storeRepository = new PizzaStoreRepository(dataSource); var optionsBuilder = new DbContextOptionsBuilder <project0Context>(); optionsBuilder.UseSqlServer(secretConfiguration.ConnectionString); //pass options builder what sql server to use and login info var options = optionsBuilder.Options; //testing serialization worked with multiple stores storeRepository.AddStore(new PizzaStore()); storeRepository.AddStore(new PizzaStore()); while (true) //loop until exit command given { Console.WriteLine("p:\tDisplay or modify pizza stores."); Console.WriteLine("s:\tSave data to disk."); Console.WriteLine("l:\tLoad data from disk."); Console.Write("Enter valid menu option, or \"exit\" to quit: "); input = Console.ReadLine(); //read command from console if (input == "p") //still need other use cases { while (true) { DisplayOrModifyStores(); input = Console.ReadLine(); if (input == "b") { break; } else if (int.TryParse(input, out var storeNum) && storeNum > 0 && storeNum <= stores.Count) //if input is a valid store number { //display chosen stores info var store = stores[storeNum - 1]; var storeString = $"\"{store.Name}\""; storeString += ", at Location: " + store.Location.ToString(); Console.WriteLine(storeString); Console.WriteLine(); //further operations! break; } else { Console.WriteLine(); Console.WriteLine($"Invalid input \"{input}\"."); Console.WriteLine(); } } } else if (input == "s") //use serializer to save data to file { SaveToFile(); } else if (input == "l") //loading data from file { LoadFromFile(); } else if (input == "exit") //exits loop and therefore program { break; } else { Console.WriteLine(); Console.WriteLine($"Invalid input \"{input}\"."); Console.WriteLine(); } } void DisplayOrModifyStores() { stores = storeRepository.GetStores().ToList(); Console.WriteLine(); if (stores.Count == 0) { Console.WriteLine("No pizza stores."); } for (var i = 1; i <= stores.Count; i++) { var store = stores[i - 1]; //indexing starts at 0 var storeString = $"{i}: \"{store.Name}\""; storeString += $", at Location: {store.Location.ToString()}"; Console.WriteLine(storeString); } Console.WriteLine(); Console.WriteLine("Enter valid menu option, or \"b\" to go back: "); } void SaveToFile() { Console.WriteLine(); stores = storeRepository.GetStores().ToList(); //get list of all pizza stores try { var serialized = JsonConvert.SerializeObject(stores, Formatting.Indented); //serialize to the file File.WriteAllTextAsync(saveLocation, serialized); Console.WriteLine("Saving Success."); } catch (SecurityException ex) { Console.WriteLine($"Error while saving: {ex.Message}"); } catch (IOException ex) { Console.WriteLine($"Error while saving: {ex.Message}"); } //other exceptions } void LoadFromFile() { Console.WriteLine(); //List<PizzaStore> stores; try { var deserialized = new List <PizzaStore>(); deserialized = JsonConvert.DeserializeObject <List <PizzaStore> >(File.ReadAllText(saveLocation)); //using (var stream = new FileStream("data.xml", FileMode.Open)) //reads from data.xml in current directory //{ // stores = (List<PizzaStore>)serializer.Deserialize(stream); //} Console.WriteLine("Loading Success."); foreach (var item in storeRepository.GetStores()) //delete current repo one restaraunt at a time { storeRepository.DeleteStore(item.Id); } foreach (var item in deserialized) //replace with repo data from file { storeRepository.AddStore(item); } } catch (FileNotFoundException) //if no save file { Console.WriteLine("No saved data found."); } catch (SecurityException ex) { Console.WriteLine($"Error while loading: {ex.Message}"); } catch (IOException ex) { Console.WriteLine($"Error while loading: {ex.Message}"); } //other exceptions? } }
public CustomersController(PizzaStoreDBContext context, PizzaStoreRepository repo) { _context = context; Repo = repo; }
public void LoadFromDB() { #region Not in use /*ingredients.Add(new Ingredients * { * * topping = "Pepperonie", * qty = 25 * * }); * * ingredients.Add(new Ingredients * { * * topping = "Sausagge", * qty = 25 * * }); * * ingredients.Add(new Ingredients * { * * topping = "Bacon", * qty = 25 * * }); * * Console.WriteLine("Inventory Populated!"); * Console.WriteLine("");*/ #endregion #region Database var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("Appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); Console.WriteLine(configuration.GetConnectionString("PizzaPalace")); #endregion var optionsBuilder = new DbContextOptionsBuilder <PizzaPalaceContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzaPalace")); var repo = new PizzaStoreRepository(new PizzaPalaceContext(optionsBuilder.Options)); var pizza = repo.GetPizzas(); //*Pizza var userin = repo.GetUserInfo(); //UserInformation var locations = repo.GetLocations(); //Locations var orderHas = repo.GetOrderHasPizzas(); //Order_Has_Pizza var orderDb = repo.GetOrders(); //Orders foreach (var item in locations) { location.Add(new Address { IdAddress = item.IdLocation, Line1 = item.LocationName } ); } foreach (var item in userin) { foreach (var item2 in locations) { if (item.LocationIdLocation == item2.IdLocation) { //add user info here to a list make a new list is what i need to do dont forget. users.Add(new User { Id = item.IdUser, Name = new Name { First = item.FirstName, Last = item.LastName }, Address = new Address { IdAddress = int.Parse(item2.IdLocation.ToString()), Line1 = item2.LocationName.ToString() } }); } } } foreach (var item in pizza) { piz.Add(new Pizza.Library.Pizza.Pizza { IdPizza = item.IdPizza, NamePizza = item.PizzaName.ToString(), CountPizza = int.Parse(item.PiizaCount.ToString()), CostPizza = decimal.Parse(item.PizzaPrice.ToString()) }); } foreach (var item in orderHas) { orderHasPizzas.Add(new OrderHasPizza { IdOrderHasPizza = item.IdOrderHasPizza, OrderIdOrder = item.OrderIdOrder, OrderLocationIdLocation = item.OrderLocationIdLocation, OrderUserIdUser = item.OrderUserIdUser, OrderUserLocationIdLocation = item.OrderUserLocationIdLocation, PizzaIdPizza = item.PizzaIdPizza, AmountOfPizzaInOrder = item.AmountOfPizzaInOrder }); } foreach (var item in orderDb) { stOrder.Add(new Store.Data.Orders { IdOrder = item.IdOrder, LocationIdLocation = item.LocationIdLocation, UserIdUser = item.UserIdUser, UserLocationIdLocation = item.UserLocationIdLocation, DateOfOrders = item.DateOfOrders, }); } try { //Method used to convert all database informtaion to process it into a List int count = 0; foreach (var itemOrd in orderDb) { if (itemOrd.IdOrder == orderHasPizzas[count].OrderIdOrder) { order.Add(new Pizza.Library.Orders { Id = int.Parse(orderHasPizzas[count].OrderIdOrder.ToString()), Location = int.Parse(orderHasPizzas[count].OrderLocationIdLocation.ToString()), User = new User { Id = int.Parse(users[count].Id.ToString()), Name = new Name { First = users[count].Name.First.ToString(), Last = users[count].Name.Last.ToString() }, Address = new Address { IdAddress = int.Parse(location[count].IdAddress.ToString()), Line1 = location[count].Line1.ToString() } }, Pizza = new Pizza.Library.Pizza.Pizza { IdPizza = int.Parse(piz[count].IdPizza.ToString()), NamePizza = piz[count].NamePizza.ToString(), CountPizza = int.Parse(piz[count].CountPizza.ToString()), CostPizza = decimal.Parse(piz[count].CostPizza.ToString()) }, AmountOfPizza = int.Parse(orderHasPizzas[count].AmountOfPizzaInOrder.ToString()), Date = DateTime.Parse(stOrder[count].DateOfOrders.ToString()) }); count++; } } } catch (FormatException ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } }
public static string BeginOrder(string name, User u, Location l, PizzaStoreRepository repo) { Console.WriteLine("View your order history?"); string ans = Console.ReadLine(); if (ans == "y") { repo.PrintOrderHistory(repo.GetOrdersByUser(u)); } Order o = new Order { User = u, UserID = repo.GetUserID(u), OrderTime = DateTime.Now, LocationID = l.LocationID, NumPizza = 0, Price = 0 }; repo.AddOrder(o); repo.Save(); o.Id = repo.GetMostRecentOrderID(); //First check if the user ordered within 2 hours //if ((repo.GetMostRecentOrderByUser(o).OrderTime - o.OrderTime).TotalMinutes < 120) //{ // return $"No, {u.FirstName}, we can't prcoess your order since you have ordered within the past 2 hours."; //} if (l.UserExistInOrderHistory(l.OrderHistory, name)) { //if the user exists, give a suggestion based on the last order... Pizza Suggested = Location.SortOrderHistory(l.OrderHistoryByUser(l.OrderHistory, name), "latest")[0].PizzaList[0]; Console.WriteLine($"You have ordered a {Suggested.PizzaSize} with {Suggested.Toppings} in the past. Would you like to add this to your order? [y/n]"); string answ = Console.ReadLine(); if (answ == "y") { o.PizzaList.Add(Suggested); o.NumPizza++; o.Price += Suggested.Price; Console.WriteLine("Would you like to order more pizzas? [y/n]"); string more = Console.ReadLine(); if (more == "n") { FinalizeOrder(l, o, repo); } } } //Now regardless of user in system or not they can order while (o.Price < 500) { if (o.NumPizza > 11) { Console.WriteLine("Cannot order more pizza since you are ordering more than 12 pizzas."); return("Failed to place order"); } //Actually begin to order Pizza p = new Pizza() { OrderID = repo.GetMostRecentOrderID(), PizzaSize = "A" }; Console.WriteLine("Please select the size of your pizza [S/M/L]"); p.PizzaSize = Console.ReadLine(); //Update pizza price based on size if (p.PizzaSize == "S") { p.Price += 10; p.PizzaSize = "S"; } if (p.PizzaSize == "M") { p.Price += 15; p.PizzaSize = "M"; } if (p.PizzaSize == "L") { p.Price += 20; p.PizzaSize = "L"; } Console.WriteLine("We have the following toppings:"); l.Toppings.ForEach(Console.WriteLine); for (var i = 0; i < l.Toppings.Count; i++) { Console.WriteLine($"Add {l.Toppings[i]}? [y/n]"); AddTopping(l, p, l.Toppings[i], Console.ReadLine(), repo); } repo.AddPizza(p); repo.Save(); p.Id = repo.GetMostRecentPizza().Id; o.PizzaList.Add(p); o.Price += p.Price; o.NumPizza++; Console.WriteLine($"You currently have {o.NumPizza} pizza(s). Would you like to order more? [y/n]"); string b = Console.ReadLine(); if (b == "n") { break; } } FinalizeOrder(l, o, repo); return("Order Finished."); }
static void Main(string[] args) { var saveLocation = "../../../../json.txt"; string input; List <PizzaStore> stores; List <Orders> orders; List <Library.Models.Customer> customers; //List<Inventory> storeInventory; var dataSource = new List <PizzaStore>(); //for initializing repo var optionsBuilder = new DbContextOptionsBuilder <project0Context>(); optionsBuilder.UseSqlServer(secretConfiguration.ConnectionString); //pass options builder what sql server to use and login info var options = optionsBuilder.Options; var dbContext = new project0Context(options); var storeRepository = new PizzaStoreRepository(dbContext); var orderRepository = new OrderRepo(dbContext); var customerRepository = new CustomerRepo(dbContext); //var inventoryRepository = new InventoryRepo(dbContext); //testing serialization worked with multiple stores //storeRepository.AddStore(new PizzaStore()); //storeRepository.AddStore(new PizzaStore()); while (true) //loop until exit command given { Console.WriteLine("p:\tDisplay or modify pizza stores."); Console.WriteLine("a:\tTo add pizza store."); Console.WriteLine("c:\tDisplay or add customers."); //Console.WriteLine("o:\tTo place order"); Console.WriteLine("s:\tSave data to disk."); //Console.WriteLine("l:\tLoad data from disk."); Console.Write("Enter valid menu option, or \"exit\" to quit: "); input = Console.ReadLine(); //read command from console if (input == "p") //still need other use cases { while (true) { DisplayOrModifyStores(); input = Console.ReadLine(); if (input == "b") { break; } else if (int.TryParse(input, out var storeNum) && storeNum > 0 && storeNum <= stores.Count) //if input is a valid store number { while (true) { //display chosen stores info var store = stores[storeNum - 1]; var storeString = $"ID: {store.Id}, Name: \"{store.Name}\""; //storeString += ", at Location: " + store.Location.ToString(); Console.WriteLine(storeString); Console.WriteLine(); Console.WriteLine("o:\tDisplay orders."); Console.WriteLine("i:\tDisplay or modify inventory"); Console.Write("Enter valid menu option, or b to go back: "); input = Console.ReadLine(); if (input == "b") { break; } else if (input == "o") { DisplayOrdersOfStore(store.Id); } else if (input == "i") { if (store.Inventory == null) { Console.WriteLine("No inventory."); } else { Console.WriteLine("Inventory: "); foreach (var item in store.Inventory) { Console.WriteLine($"Item Name: \"{item.Key}\", " + $"Item Quantity: \"{item.Value}\""); } } while (true) { Console.WriteLine("a:\tAdd inventory item."); Console.Write("Enter valid menu option, or b to go back: "); input = Console.ReadLine(); if (input == "a") { Dictionary <string, int> inv = store.Inventory; AddInventoryItem(ref inv); store.Inventory = inv; storeRepository.UpdateStore(store); } else if (input == "b") { break; } } } } } else { Console.WriteLine(); Console.WriteLine($"Invalid input \"{input}\"."); Console.WriteLine(); } } } else if (input == "a") { AddNewPizzaStore(); } else if (input == "c") { while (true) { DisplayAddOrModifyCustomers(); input = Console.ReadLine(); if (input == "b") { break; } else if (input == "a") { AddNewCustomer(); } else if (int.TryParse(input, out var custNum) && custNum > 0 && custNum <= customers.Count) //if input is a valid store number { while (true) { //display chosen stores info var cust = customers[custNum - 1]; var custString = $"ID: {cust.Id}, Name: \"{cust.FirstName} {cust.LastName}\""; Console.WriteLine(custString); Console.WriteLine("c:\tModify customer"); Console.Write("Enter valid menu option, or b to go back: "); input = Console.ReadLine(); if (input == "b") { break; } else if (input == "c") { ////Modify Customer!!!!!!! } } } } } //else if (input == "o") //{ //} else if (input == "s") //use serializer to save data to file { SaveToFile(); } //else if (input == "l") //loading data from file //{ // LoadFromFile(); //} else if (input == "exit") //exits loop and therefore program { break; } else { Console.WriteLine(); Console.WriteLine($"Invalid input \"{input}\"."); Console.WriteLine(); } } void DisplayAddOrModifyCustomers() { customers = customerRepository.GetAllCustomer().ToList(); Console.WriteLine(); if (customers.Count == 0) { Console.WriteLine("No customers."); } else { for (var i = 1; i <= customers.Count; i++) { var customer = customers[i - 1]; //indexing starts at 0 var custString = $"{i}: \"{customer.FirstName} {customer.LastName}\" "; //storeString += $", at Location: {store.Location.ToString()}"; Console.WriteLine(custString); } } Console.WriteLine("a:\tAdd customer."); Console.WriteLine(); Console.WriteLine("Enter valid menu option, or \"b\" to go back: "); } void DisplayOrModifyStores() { stores = storeRepository.GetStores().ToList(); Console.WriteLine(); if (stores.Count == 0) { Console.WriteLine("No pizza stores."); } for (var i = 1; i <= stores.Count; i++) { var store = stores[i - 1]; //indexing starts at 0 var storeString = $"{i}: \"{store.Name}\""; //storeString += $", at Location: {store.Location.ToString()}"; Console.WriteLine(storeString); } Console.WriteLine(); Console.WriteLine("Enter valid menu option, or \"b\" to go back: "); } void DisplayOrdersOfStore(int id) { orders = orderRepository.GetOrdersOfLocation(id).ToList(); Console.WriteLine(); if (orders.Count == 0) { Console.WriteLine("No orders."); } for (var i = 1; i <= orders.Count; i++) { var order = orders[i - 1]; //indexing starts at 0 var ordString = $"{i}: Store\\: \"{order.StoreId}\", Customer\\: " + $"\"{order.CustomerId}\", Time\\: \"{order.OrderTime}"; Console.WriteLine(ordString); } } PizzaStore AddNewPizzaStore() { Console.WriteLine(); string name = null; //Library.Models.Address address = null; Dictionary <string, int> inventory = null; while (true) { Console.Write("Would you like to use the default name? (y/n)"); input = Console.ReadLine(); if (input == "y") { break; } else if (input == "n") { Console.Write("Enter the new pizza restaurant's name: "); name = Console.ReadLine(); break; } } //while (true) //{ // Console.Write("Would you like to use a default location? (y/n)"); // input = Console.ReadLine(); // if (input == "y") // { // break; // } // else if (input == "n") // { // address = NewAddress(); // break; // } //} while (true) { Console.Write("Would you like to use the default inventory? (y/n)"); input = Console.ReadLine(); if (input == "y") { break; } else if (input == "n") { inventory = NewInventory(); break; } } //PizzaStore restaurant = new PizzaStore(name, inventory, address); PizzaStore restaurant = new PizzaStore(name, inventory); storeRepository.AddStore(restaurant); return(restaurant); } void AddNewCustomer() { Console.WriteLine(); Console.Write("Enter the new customer's firstname: "); string firstname = Console.ReadLine(); Console.Write("Enter the new customer's lastname: "); string lastname = Console.ReadLine(); PizzaStore store; while (true) { Console.Write("Would you like to use the default store? (y/n)"); input = Console.ReadLine(); if (input == "y") { store = new PizzaStore(); break; } else if (input == "n") { while (true) { Console.Write("Would you like to use a new store? (y/n)"); input = Console.ReadLine(); if (input == "y") { store = AddNewPizzaStore(); break; } else if (input == "n") { Console.Write("Enter existing store id: "); input = Console.ReadLine(); store = storeRepository.GetStoreById(Convert.ToInt32(input)); break; } } break; } } Library.Models.Customer cust = new Library.Models.Customer(firstname, lastname, store); customerRepository.AddCustomer(cust); } void AddInventoryItem(ref Dictionary <string, int> inv) { Console.WriteLine("Enter the new item's name: "); string name = Console.ReadLine(); Console.WriteLine("Enter the new item's amount: "); int amount = Convert.ToInt32(Console.ReadLine()); inv.Add(name, amount); Console.WriteLine("Added"); } Dictionary <string, int> NewInventory() { Dictionary <string, int> inventory = new Dictionary <string, int>(); while (true) { Console.Write("Would you like to add an inventory item? (y/n)"); input = Console.ReadLine(); if (input == "y") { try { AddInventoryItem(ref inventory); } catch (ArgumentException e) { //log it Console.WriteLine(e.Message); return(inventory); } } else if (input == "n") { break; } } return(inventory); } //Library.Models.Address NewAddress() //{ // string street, city, state, zipcode, country; // Console.Write("Enter the new pizza restaurant's location - street: "); // street = Console.ReadLine(); // Console.Write("Enter the new pizza restaurant's location - city: "); // city = Console.ReadLine(); // Console.Write("Enter the new pizza restaurant's location - state: "); // state = Console.ReadLine(); // Console.Write("Enter the new pizza restaurant's location - zipcode: "); // zipcode = Console.ReadLine(); // Console.Write("Enter the new pizza restaurant's location - country: "); // country = Console.ReadLine(); // try // { // return new Library.Models.Address(street, city, state, zipcode, country); // } // catch (ArgumentException ex) // { // Console.WriteLine(ex.Message); // } // return null; //} void SaveToFile() { Console.WriteLine(); stores = storeRepository.GetStores().ToList(); //get list of all pizza stores try { var serialized = JsonConvert.SerializeObject(stores, Formatting.Indented); //serialize to the file File.WriteAllTextAsync(saveLocation, serialized); Console.WriteLine("Saving Success."); } catch (SecurityException ex) { Console.WriteLine($"Error while saving: {ex.Message}"); } catch (IOException ex) { Console.WriteLine($"Error while saving: {ex.Message}"); } //other exceptions } //void LoadFromFile() //{ // Console.WriteLine(); // try // { // var deserialized = new List<PizzaStore>(); // deserialized = JsonConvert.DeserializeObject<List<PizzaStore>>(File.ReadAllText(saveLocation)); // if (deserialized != null) // { // deserialized.ToList(); // } // Console.WriteLine("Loading Success."); // var allStores = storeRepository.GetAllStores().ToList(); // foreach (var item in allStores) //delete current repo one restaraunt at a time // { // //try // //{ // storeRepository.DeleteStore(item); //throws error! // //} // //catch (ArgumentOutOfRangeException e) // //{ // // Console.WriteLine(e.Message); // //} // } // if (deserialized != null) // { // foreach (var item in deserialized) //replace with repo data from file // { // storeRepository.AddStore(item); // } // } // } // catch (FileNotFoundException) //if no save file // { // Console.WriteLine("No saved data found."); // } // catch (SecurityException ex) // { // Console.WriteLine($"Error while loading: {ex.Message}"); // } // catch (IOException ex) // { // Console.WriteLine($"Error while loading: {ex.Message}"); // } // //other exceptions? //} }