Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var loader = new ProductLoader();

            try
            {
                Console.WindowWidth = 150;
                bool terminate = false;
                while (terminate == false)
                {
                    Console.Clear();
                    Console.WriteLine("Welcome to VirtusFit application.");
                    Console.WriteLine("----------------------------------");
                    Console.WriteLine("Available options:");
                    Console.WriteLine("1. Display full list of products.");
                    Console.WriteLine("2. Search for products.");
                    Console.WriteLine("3. Add new product.");
                    Console.WriteLine("4. Edit product.");
                    Console.WriteLine("5. Prepare diet plan.");
                    Console.WriteLine("6. Close application.");
                    Console.WriteLine("----------------------------------");
                    Console.WriteLine("Please choose your action:");
                    string userChoice = (Console.ReadLine());
                    if (userChoice != "1" && userChoice != "2" && userChoice != "3" && userChoice != "4" && userChoice != "5" && userChoice != "6")
                    {
                        Console.WriteLine("Incorrect input");
                        Console.WriteLine();
                        Console.WriteLine("Press any key to continue.");
                        Console.ReadKey();
                    }
                    else
                    {
                        int _userChoice = int.Parse(userChoice);
                        switch (_userChoice)
                        {
                        case 1:
                            DisplayProductList.DisplayList(ListOfProducts);
                            break;

                        case 2:
                            SearchProductConsoleInterface newSearch = new SearchProductConsoleInterface();
                            newSearch.SearchProductInterface(ListOfProducts);
                            break;

                        case 3:
                            AddProductFromConsole();
                            break;

                        case 4:
                            DisplayProductList.DisplayList(ListOfProducts);
                            EditDataFromConsoleInterface testInterface = new EditDataFromConsoleInterface();
                            testInterface.EditProductInterface();
                            break;

                        case 5:
                            Console.WriteLine("There will be a super cool diet planner");
                            Console.WriteLine();
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                            break;

                        case 6:
                            terminate = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"An error occured: {e.Message} \nPress any key.");
                Console.ReadKey();
            }
        }
        public void SearchProductInterface(List <Product> productList)
        {
            Console.WriteLine();
            Console.WriteLine("Choose the type of searching:");
            var    cursorPos = Console.CursorTop;
            string userDecision;

            do
            {
                userDecision = DisplayOptions(cursorPos);
            } while (userDecision != "Search by name" && userDecision != "Search by calories" && userDecision != "Search by fat" && userDecision != "Search by carbohydrates" && userDecision != "Search by protein");

            switch (userDecision)
            {
            case "Search by name":
            {
                _newData.GetDataFromUser(out var productName);
                var searchList = _newSearch.SearchByName(productList, productName);
                DisplayProductList.DisplayList(searchList);
                break;
            }

            case "Search by calories":
            {
                var searchValue = _newData.GetDataFromUser(out var minValue, out var maxValue);
                if (searchValue != 0)
                {
                    var searchList = _newSearch.SearchByCalories(productList, searchValue);
                    DisplayProductList.DisplayList(searchList);
                }
                else
                {
                    var searchList = _newSearch.SearchByCalories(productList, minValue, maxValue);
                    DisplayProductList.DisplayList(searchList);
                }
                break;
            }

            case "Search by fat":
            {
                string macro       = "fat";
                var    searchValue = _newData.GetDataFromUser(macro, out var minValue, out var maxValue);
                if (searchValue != 0)
                {
                    var searchList = _newSearch.SearchByFat(productList, searchValue);
                    DisplayProductList.DisplayList(searchList);
                }
                else
                {
                    var searchList = _newSearch.SearchByFat(productList, minValue, maxValue);
                    DisplayProductList.DisplayList(searchList);
                }
                break;
            }

            case "Search by carbohydrates":
            {
                string macro       = "carbohydrates";
                var    searchValue = _newData.GetDataFromUser(macro, out var minValue, out var maxValue);
                if (searchValue != 0)
                {
                    var searchList = _newSearch.SearchByCarbohydrates(productList, searchValue);
                    DisplayProductList.DisplayList(searchList);
                }
                else
                {
                    var searchList = _newSearch.SearchByCarbohydrates(productList, minValue, maxValue);
                    DisplayProductList.DisplayList(searchList);
                }
                break;
            }

            case "Search by protein":
            {
                string macro       = "protein";
                var    searchValue = _newData.GetDataFromUser(macro, out var minValue, out var maxValue);
                if (searchValue != 0)
                {
                    var searchList = _newSearch.SearchByProteins(productList, searchValue);
                    DisplayProductList.DisplayList(searchList);
                }
                else
                {
                    var searchList = _newSearch.SearchByProteins(productList, minValue, maxValue);
                    DisplayProductList.DisplayList(searchList);
                }
                break;
            }
            }
        }