Exemple #1
0
        /// <summary>
        /// Calls DatabaseControl to GetAllProducts and Display those of the Type
        /// the user selected.
        /// Calls InputControl to get the users selection and returns directions for
        /// the NextPage and the Product the user chose (ProductToBuy = null if user chose to go back)
        /// </summary>
        /// <param name="Type">NextPage, ProductToBuy</param>
        /// <returns></returns>
        internal static (string, Product) DisplayProductPage(string Type)
        {
            string  NextPage     = "GO BACK";
            Product ProductToBuy = null;

            int NumProducts = 1;

            List <Product> Products       = DatabaseControl.GetAllProducts();
            List <Product> ProductsOfType = new List <Product>();

            foreach (Product p in Products)
            {
                if (p.Type == Type)
                {
                    Console.WriteLine($"\nProduct {NumProducts}:");
                    Console.WriteLine($"Name: {p.Name}");
                    Console.WriteLine($"Price: {p.Price}");
                    Console.WriteLine($"Description: {p.Description}");
                    ProductsOfType.Add(p);
                    NumProducts++;
                }
            }
            NumProducts--;

            Console.WriteLine("\nEnter a number to add a product to your cart or enter 0 to go back");
            int choice = InputControl.VerifyListChoiceStartingAt0(NumProducts);

            if (choice != -1)
            {
                ProductToBuy = ProductsOfType[choice];
                NextPage     = "LOCATIONS WITH PRODUCT";
            }
            return(NextPage, ProductToBuy);
        }