コード例 #1
0
        private void ViewColors()
        {
            List <Product> colors = _shopBL.GetAllColors();

            if (colors.Count == 0)
            {
                Console.WriteLine("No products in database. You should add some.");
            }
            else
            {
                Console.WriteLine("Full selection: ");

                int i = 0;
                foreach (Product color in colors)
                {
                    Console.WriteLine("[" + ++i + "]" + color.ToString());
                }

                bool repeat = true;
                // TODO: add to cart
                Console.WriteLine("Choose which Product you would like to add to cart. Otherwise type [0] to go back.");
                do
                {
                    string input = Console.ReadLine();
                    int    n;
                    if (int.TryParse(input, out n))
                    {
                        if (input == "0")
                        {
                            Console.WriteLine("Returning to Products Menu...");
                            repeat = false;
                        }
                        else if (n <= colors.Count)
                        {
                            Console.WriteLine("You chose " + colors[n - 1].Name);
                            // add to cart here
                        }
                        else
                        {
                            Console.WriteLine("invalid input");
                        }
                    }
                    else
                    {
                        Console.WriteLine("invalid input");
                    }
                } while(repeat);
            }
        }