/// <summary> /// Method for checking if the files in specific path exists /// If not, creates an empty file with the specified name in path /// </summary> static public void InitializeReading() { try { stock = fileInterface.ReadStockFile(StockCsv); menu = fileInterface.ReadMenuFile(MenuCsv); orders = fileInterface.ReadOrdersFile(OrdersCsv, menu); } catch (IOException) { Console.WriteLine(" ERROR: Close open .csv files and try again!"); Environment.Exit(0); } }
/// <summary> /// Method for creating an order /// Separated from the rest in order to test /// </summary> /// <param name="newOrder">New order item</param> /// <param name="OrderPath">Path to orders csv file</param> /// <param name="StockPath">Path to stock csv file</param> /// <param name="orders">Orders object</param> /// <param name="stock">Stock object</param> static public void AddElement(OrderItem newOrder, string OrderPath, string StockPath, RestaurantStock stock, RestaurantOrders orders) { List <int> productIds = newOrder.GetProductIds(); /// Cycle trough items bool canBeAdded = true; foreach (int i in productIds) { /// Check if the component can be added if (stock.GetItemByID(i).CheckIfEnoughInStock()) { canBeAdded = true; } else { canBeAdded = false; break; } } if (!canBeAdded) { Console.WriteLine(" Error: There is not enough of product for this order!\r\n"); } else if (orders.AddNewEntry(newOrder)) { List <StockItem> updatedStock = new List <StockItem>(); /// Reduce components foreach (int i in productIds) { updatedStock.Add(stock.GetItemByID(i)); stock.GetItemByID(i).UpdateElement(); } Console.WriteLine(" Item added succesfully\r\n"); fileInterface.UpdateEntryInFile(StockPath, updatedStock); fileInterface.AddEntryToFile(OrderPath, newOrder); } else { Console.WriteLine(" Error: Item was not added\r\n"); } }
/// <summary> /// Method for removing element from stock list and file /// </summary> /// <param name="filePath">Path to stock file</param> /// <param name="list">RestaurantStock object, where stock is saved in memory</param> /// <param name="removableID">Removable item id</param> /// <param name="orders">RestaurantOrders reference object, where orders are saved</param> static public void RemoveElement(string filePath, RestaurantMenu list, int removableID, RestaurantOrders orderList) { /// Check if there are orders with this item, else removal is cancelled List <int> usedIn = orderList.GetAllOrderMenuItems(); if (usedIn.Contains(removableID)) { Console.WriteLine(" Cannot remove element as it exists in orders!"); } else if (list.DoesItemExistsByID(removableID)) { list.RemoveItem(removableID); fileInterface.DeleteEntryFromFile(filePath, removableID); Console.WriteLine(" Item removed succesfully\r\n"); } else { Console.WriteLine(" Element with specified ID does not exist!"); } }