コード例 #1
0
 /// <summary>
 /// Method for updating StockItem element in array and Restaurant stock file
 /// </summary>
 /// <param name="refStock">Reference to RestaurantStock object</param>
 /// <param name="item">Updated item</param>
 /// <param name="path">Path to Restaurant Stock file</param>
 public static void UpdateElement(RestaurantStock refStock, StockItem item, string path)
 {
     if (refStock.UpdateItem(item))
     {
         fileInterface.UpdateEntryInFile(path, item);
         Console.WriteLine(" Item was updated succesfully\r\n");
     }
     else
     {
         Console.WriteLine(" Item was not updated!\r\n");
     }
 }
コード例 #2
0
 /// <summary>
 /// Method for adding a new MenuItem element into array and csv file
 /// </summary>
 /// <param name="stockRef">RestaurantStock reference, to which new element will be added</param>
 /// <param name="item">New addable StockItem element</param>
 /// <param name="filePath">Path to RestaurantStock file</param>
 static public void AddElement(RestaurantStock stockRef, StockItem item, string filePath)
 {
     if (stockRef.AddNewEntry(item))
     {
         Console.WriteLine(" Item added succesfully\r\n");
         fileInterface.AddEntryToFile(filePath, item);
     }
     else
     {
         Console.WriteLine(" Error: Item was not added\r\n");
     }
 }
コード例 #3
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>
 static public void RemoveElement(string filePath, RestaurantStock list, int removableID)
 {
     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!");
     }
 }
コード例 #4
0
 /// <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);
     }
 }
コード例 #5
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");
            }
        }