/// <summary>
        /// Handles input and Output of the Print Wine List Menu
        /// </summary>
        /// <param name="wineCollection"></param>
        public void GetUserInputPrintWineListMenu(WineAPI wineCollection)
        {
            this.PrintWineListMenu();
            string inputString = InputCharReturnString();

            while (inputString != "1" && inputString != "2" && inputString != "3" && inputString != "4" && inputString != "5")
            {
                Console.WriteLine(WriteInvalidEntry());
                this.PrintWineListMenu();
                inputString = InputCharReturnString();
            }
            Console.WriteLine("Connecting to database, this may take a while.");

            //Output the list of wines by calling the appropriate sorting the user wants
            switch (inputString)
            {
            case "1":
                PrintOutput(wineCollection.CreateListStringUnordered());
                break;

            case "2":
                PrintOutput(wineCollection.CreateListStringOrderByName());
                break;

            case "3":
                PrintOutput(wineCollection.CreateListStringOrderByHighestPrice());
                break;

            case "4":
                PrintOutput(wineCollection.CreateListStringOrderByLowestPrice());
                break;
            }
        }
        /// <summary>
        /// Input sequence to create a new WineItem that calls a method to add it to the WineItem array.
        /// </summary>
        /// <param name="WineCollection">WineItem[]</param>
        public void AddWine(WineAPI WineCollection)
        {
            string idInput = GetId();
            //Check if the id the user input is all ready in the database
            string seachString = WineCollection.SearchByAndPossiblyDelete(idInput, nameof(Beverage.id), false);

            if (seachString.Contains("was not found"))
            {
                //Get the Name of the wine
                string descriptionInput = GetTheNameOfTheWine();

                //Get the Wine pack
                string packInput = GetTheWinePack();

                //Get the price
                decimal priceInputDec = GetThePrice();

                //Get if the wine is active
                bool wineActive = BoolInput("Is this wine active");

                //Now that all the input has been recieved by the user call the method to add the wine
                WineCollection.AddNewItem(idInput, descriptionInput, packInput, priceInputDec, wineActive);

                //Output the wine that has been added
                Console.WriteLine(WineCollection.SearchByAndPossiblyDelete(idInput, nameof(Beverage.id), false));
            }
            else
            {
                Console.WriteLine(idInput + " is allready used as an ID. Each ID must be unique.");
            }
        }
        /// <summary>
        /// Get id from user of wine to update and launches UpdateWine in the WineAPI using the ID
        /// from the user.
        /// </summary>
        /// <param name="WineCollection">WineAPI</param>
        public void GetUserInputToUpdateAWine(WineAPI WineCollection)
        {
            string idInput = GetId();
            //Check if the id the user input is all ready in the database
            string seachString = WineCollection.SearchByAndPossiblyDelete(idInput, nameof(Beverage.id), false);

            if (seachString.Contains("was not found"))
            {
                Console.WriteLine(idInput + " Id was not found so can not be edited.");
            }
            else
            {
                //As the id was found to be used in the database launch the UpdateWine
                WineCollection.UpdateWine(idInput);
            }
        }
Beispiel #4
0
    {//This file will handle the logic needed to run the menus in the userInterface.
        static void Main(string[] args)
        {
            //****************************
            //Class Variables
            //****************************

            //Create an instance of the WineAPI for use in program
            WineAPI wineItemCollection = new WineAPI();

            //Instance of the UserInterface class to run the menus'
            UserInterface ui = new UserInterface();

            //Start the User Interface and initialize it
            ui.StartUserInterface();

            //Start the main menu and wit for user input
            int choice = ui.GetUserInputMainMenu();

            //As long as the user does not choose 5 for exiting loop through the main menu
            while (choice != 6)
            {
                switch (choice)
                {
                case 1:    //Go to the Print Wine List Menu in the User Interface
                    ui.GetUserInputPrintWineListMenu(wineItemCollection);
                    break;

                case 2:    //Go to the method SearchForWineAndPossiblyDelete and choose search only
                    SearchForWineAndPossiblyDelete(wineItemCollection, false);
                    break;

                case 3:    //Go to the method in the User Interface to add a wine item
                    ui.AddWine(wineItemCollection);
                    break;

                case 4:    //Go to the method SearchForWineAndPossiblyDelete and choose search and delete
                    SearchForWineAndPossiblyDelete(wineItemCollection, true);
                    break;

                case 5:
                    ui.GetUserInputToUpdateAWine(wineItemCollection);
                    break;
                }
                choice = ui.GetUserInputMainMenu();
            }
        }
        /// <summary>
        /// Searches the property for a value input by the user and outputs if found
        /// </summary>
        /// <param name="WineCollection">WineItem[]</param>
        /// <param name="propertyName">string</param>
        public void SearchBy(WineAPI WineCollection, string propertyName, bool delete)
        {
            string input;

            if (propertyName == "active")
            {
                input = BoolInput("Do you want the active wines").ToString();
            }
            else
            {
                ColorLineNoEnter($"Enter {propertyName}: ");
                input = Console.ReadLine();
            }

            if (input == "")
            {
                Console.WriteLine(WriteInvalidSpecificEntry(propertyName));
            }
            else
            {
                Console.WriteLine(WineCollection.SearchByAndPossiblyDelete(input, propertyName, delete));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Method used to find out the choice of property the user wants to find or delete
        /// </summary>
        /// <param name="WineCollection">WineAPI</param>
        /// <param name="delete">bool</param>
        static void SearchForWineAndPossiblyDelete(WineAPI WineCollection, bool delete)
        {
            //Create an instance of the User Interface
            UserInterface ui = new UserInterface();
            //Output the Search or Delete Menu and wait for users choice
            int choice = ui.GetUserInputSearchMenu(delete);

            //Repeat until the user chooses 6 to exit
            while (choice != 6)
            {
                //Using the choice input by the user, get the input of the property type
                //needed from the user.
                switch (choice)
                {
                case 1:
                    ui.SearchBy(WineCollection, nameof(Beverage.id), delete);
                    break;

                case 2:
                    ui.SearchBy(WineCollection, nameof(Beverage.name), delete);
                    break;

                case 3:
                    ui.SearchBy(WineCollection, nameof(Beverage.pack), delete);
                    break;

                case 4:
                    ui.SearchBy(WineCollection, nameof(Beverage.price), delete);
                    break;

                case 5:
                    ui.SearchBy(WineCollection, nameof(Beverage.active), delete);
                    break;
                }
                choice = ui.GetUserInputSearchMenu(delete);
            }
        }