public static void AddPizzaInventory(Store store) { Console.WriteLine("================================"); Console.WriteLine(""); Console.WriteLine("Current Inventory"); Console.WriteLine("-----------------"); Console.WriteLine($"Stock | Pizza"); Console.WriteLine("-------------------------------"); foreach (var sp in _spr.GetPerStore(store)) { Pizza pizza = _pr.GetPizza(sp.PizzaId); Console.WriteLine($" {sp.Inventory} | {pizza.Name}"); } Console.WriteLine(""); Console.WriteLine("Enter the number of pizzas to add(+) or subtract(-) per type, if none put 0"); foreach (var p in _spr.GetPerStore(store)) { Pizza pizza = _pr.GetPizza(p.PizzaId); Console.Write($"{pizza.Name}: "); string add = Console.ReadLine(); int result; bool check = int.TryParse(add, out result); while (!check) { Console.WriteLine(""); Console.Write("Not valid, must be a number, please try again: "); add = Console.ReadLine(); Console.WriteLine(""); check = int.TryParse(add, out result); } int new_inventory = p.Inventory + Int32.Parse(add); bool check2 = new_inventory >= 0; while (!check2) { Console.WriteLine(""); Console.Write("Not valid, the total inventory can't be negative, please try again: "); add = Console.ReadLine(); new_inventory = p.Inventory + Int32.Parse(add); check2 = new_inventory >= 0; Console.WriteLine(""); } UpdateInventory(store, pizza, new_inventory); } Console.WriteLine(""); Console.WriteLine($"{store.Name}, the inventory is updated!"); Console.WriteLine(""); }
public IHttpActionResult GetPizza(int pizzaId) { PizzaRepository pizza = new PizzaRepository(); var pizzaReceived = pizza.GetPizza(pizzaId); if (pizzaReceived != null) { return(Ok(pizzaReceived)); } else { return(NotFound()); } }
public IActionResult OrderHistory(OrderViewModel model) { List<OrderModel> orders; try { _ = userLoggedIn; // exception not caught if you just use uLI orders = _repo.GetOrdersForUser(userLoggedIn); } catch (NullReferenceException) { model.ReasonForError = "You are not logged in. Please return to the main page to login and try again."; return View("Error", model); } List<OrderViewClass> orderHistory = new List<OrderViewClass>(); foreach (OrderModel order in orders) { StringBuilder toppings = new StringBuilder(); foreach (string topping in order.Toppings.Split(',')) { int toppingID; if (!int.TryParse(topping, out toppingID)) { Console.WriteLine($"Database error: Expected integer for pizza ID, received {topping}"); toppings.Append("Error, "); continue; } ToppingModel top = _repo.GetTopping(toppingID); toppings.Append($"{top.Name}, "); } toppings.Remove(toppings.Length - 2, 2); OrderViewClass orderView = new OrderViewClass{ OrderID = order.OrderID, Created = order.Created, Size = order.Size, Crust = _repo.GetCrust(order.CrustID).Name, Toppings = toppings.ToString(), Quantity = order.Quantity, Cost = order.TotalCost, StoreName = _repo.GetStore(order.StoreID).Name }; if (order.PizzaID == 0) { orderView.Pizza = "Custom"; } else { try { orderView.Pizza = _repo.GetPizza(order.PizzaID).Name; } catch (NullReferenceException) { Console.WriteLine($"Database error: Could not find a pizza with ID {order.PizzaID} in the Pizza table"); orderView.Pizza = "Error"; } } orderHistory.Add(orderView); } model.OrderHistory = orderHistory; return View(model); }
public PizzaViewModel(string id) { //Get List of Pizza associated with the store id. Pizzas = _ps.GetPizza(System.Convert.ToInt64(id)); // Sizes = _ps.GetSize(); }
public IActionResult Visit(int ID) { StoreModel store; try { store = _repo.GetStore(ID); } catch (SqlException e) { if (e.Message.Contains("server was not found")) { Console.WriteLine("Could not connect to the SQL database"); StoreViewModel thisModel = new StoreViewModel(); thisModel.ReasonForError = "An internal error has occured. Please return to the main page and try again."; return(View("Error", thisModel)); } throw e; } if (store == null) { StoreViewModel thisModel = new StoreViewModel(); thisModel.ReasonForError = $"A store with an ID of {ID} does not exist. Please enter a different ID from the URL, or select a store from the selection page after logging in."; return(View("Error", thisModel)); } List <MenuModel> items = _repo.GetMenu(ID); List <PizzaModel> pizzas = new List <PizzaModel>(); List <CheckModel> pizzasToSelectFrom = new List <CheckModel>(); List <ToppingModel> toppings = _repo.GetToppings(); foreach (MenuModel item in items) { PizzaModel pizza = _repo.GetPizza(item.PizzaID); if (pizza == null) { Console.WriteLine($"Unknown pizza found with ID {item.PizzaID} from store {item.StoreID} at menu ID {item.ID}"); continue; } string[] temp = pizza.DefaultToppings.Split(','); int[] defaultToppingIDs = new int[temp.Length]; for (int i = 0; i < temp.Length; i++) { if (!int.TryParse(temp[i], out defaultToppingIDs[i])) { Console.WriteLine($"Database error: Expected integer for default topping ID in pizza {pizza.ID}, got {temp[i]}"); continue; } } pizzas.Add(pizza); CrustModel crust = _repo.GetCrust(pizza.DefaultCrustID); ToppingViewModel[] toppingsSelected = new ToppingViewModel[toppings.Count()]; for (int i = 0; i < toppingsSelected.Length; i++) { ToppingModel topping = toppings[i]; toppingsSelected[i] = new ToppingViewModel { ID = topping.ID, Name = topping.Name, IsSelected = defaultToppingIDs.Contains(topping.ID) }; } pizzasToSelectFrom.Add(new CheckModel { ID = pizza.ID, Name = pizza.Name, Checked = false, Cost = pizza.Cost, DefaultCrust = crust.ID, SelectedCrust = crust.ID.ToString(), SelectedToppings = toppingsSelected }); } List <SelectListItem> crustDropDownOptions = new List <SelectListItem>(); foreach (CrustModel crust in _repo.GetCrusts()) { crustDropDownOptions.Add(new SelectListItem { Text = crust.Name, Value = crust.ID.ToString() }); } StoreViewModel model = new StoreViewModel(); model.StoreName = store.Name; model.Menu = pizzasToSelectFrom; try { _ = userLoggedIn; // keeps the session data alive } catch (NullReferenceException) { // people can view menus if they're not logged in, but not order } model.Crusts = crustDropDownOptions; model.Toppings = toppings; TempData["StoreID"] = store.ID; TempData.Keep("StoreID"); return(View(model)); }