public Manager(string productStockFile, string menuFile, string ordersFile) { productStock = new ProductStock(); productStock.getDataFromFile(productStockFile); menu = new Menu(); menu.getDataFromFile(menuFile); orders = new Orders(); orders.getDataFromFile(ordersFile); this.productStockFile = productStockFile; this.menuFile = menuFile; this.ordersFile = ordersFile; }
public void createOrderPage() { Console.Clear(); Console.WriteLine("Menu items"); this.menu.printMenu(); Console.WriteLine("\n"); try { int id = this.orders.newID(); Console.Write("Menu items: "); var menuIdsString = Console.ReadLine(); var menuIds = menuIdsString.Split(' ').Select(Int32.Parse).ToList(); // create temporary variable for productStock // deduct each product // if product stock is not below 0 // this.productStock = tempProductStock var tempProductStock = new ProductStock(); tempProductStock.getDataFromFile(this.productStockFile); // check if all given menu items are available in the menu foreach (var menuId in menuIds) { if (this.menu.isAvailable(menuId) == false) { Console.WriteLine("Menu items are not available!"); Console.ReadKey(); orderPage(); } else { var menuItem = this.menu.getMenuListItem(menuId); foreach (var productId in menuItem.products) { tempProductStock.deductStock(productId); if (tempProductStock.getStock(productId) < 0) { Console.WriteLine("Products are not available! Order cancelled"); Console.ReadKey(); orderPage(); } } } } // given product count must be > 0 if (menuIds.Count > 0) { // replace original productStock list with list with deducted values this.productStock = tempProductStock; this.productStock.updateDataFile(this.productStockFile); var orderItem = new OrderItem(id, DateTime.Now, menuIds); this.orders.createOrder(orderItem); this.orders.updateDataFile(this.ordersFile); Console.WriteLine("Order has been created successfully"); Console.ReadKey(); } else { Console.WriteLine("Menu item count must be > 0"); Console.ReadKey(); } } catch (Exception e) { //Console.WriteLine(e); Console.WriteLine("Error while adding item to menu!"); Console.ReadKey(); } orderPage(); }