/// <summary> /// Method for updating MenuItem element in array and Restaurant Menu csv file /// </summary> /// <param name="refMenu">Reference to RestaurantMenu object</param> /// <param name="item">Updated item</param> /// <param name="path">Path to Restaurant Menu file</param> public static void UpdateElement(RestaurantMenu refMenu, MenuItem item, string path) { if (refMenu.UpdateItem(item)) { fileInterface.UpdateEntryInFile(path, item); Console.WriteLine(" Item was updated succesfully\r\n"); } else { Console.WriteLine(" Item was not updated!\r\n"); } }
/// <summary> /// Method for adding a new MenuItem element into array and csv file /// </summary> /// <param name="menuRef">RestaurantMenu reference, to which new element will be added</param> /// <param name="item">New addable MenuItem element</param> /// <param name="filePath">Path to RestaurantMenu file</param> static public void AddElement(RestaurantMenu menuRef, MenuItem item, string filePath) { if (menuRef.AddNewEntry(item)) { Console.WriteLine(" Item added succesfully\r\n"); fileInterface.AddEntryToFile(filePath, item); } else { Console.WriteLine(" Error: Item was not added\r\n"); } }
/// <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 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!"); } }