コード例 #1
0
        private void Shopping()
        {
            var stockManager = new StockManager();

            _catalog = stockManager.GetProducts();
            bool isFinished = false;

            while (!isFinished)
            {
                Console.Clear();
                PrintHeader();
                Console.WriteLine("\nB: Buy item     R: Release item    F: Print bill");
                Console.Write("ACTION (B/R/F): ");
                var action = Console.ReadKey().Key;
                switch (action)
                {
                case ConsoleKey.B:
                    Console.Write("\nCHOICE (product name): ");
                    string product = Console.ReadLine();
                    Console.Write("QUANTITY (number): ");
                    int quantity = int.Parse(Console.ReadLine());
                    try
                    {
                        var itemLine = stockManager.ReserveItem(quantity, product);
                        _card[itemLine.Item.Name] = itemLine;
                        Console.WriteLine($"{itemLine.Item.Name} added.");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                case ConsoleKey.R:
                    Console.Write("\nPRODUCT TO RELEASE (product name): ");
                    string productName = Console.ReadLine();
                    try
                    {
                        stockManager.ReleaseItem(_card[productName]);
                        _card.Remove(productName);
                        Console.WriteLine("Product released !");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                    break;

                case ConsoleKey.F:
                    isFinished = true;
                    break;
                }
                Console.WriteLine("\nPress any key to continue ...");
                Console.ReadKey();
            }
            stockManager.Close();
        }