Esempio n. 1
0
        static void Main(string[] args)
        {
            //Expands the console for easier viewing
            Console.SetWindowSize(150, 40);

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the wine database
            BeverageJAckermanEntities beverageEntities = new BeverageJAckermanEntities();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                beverageEntities.SaveChanges();
                switch (choice)
                {
                    case 1:
                        //Print Entire List Of Items
                        userInterface.DisplayAllItems(beverageEntities);
                        break;

                    case 2:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();
                        Beverage foundWine = beverageEntities.Beverages.Find(searchQuery);
                        if (foundWine != null)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("");
                            Console.WriteLine("Here is the wine with that ID:");
                            Console.WriteLine(foundWine.id + " " + foundWine.name + " " + foundWine.pack + " " + foundWine.price);
                        }
                        else
                        {
                            Console.WriteLine("Sorry, no wine with that ID could be found. the ID you entered may be incorrect or does not exist in the database.");
                        }

                        break;

                    case 3:
                        //Add A New Item To The List
                        string ID;
                        string Name;
                        decimal Price;
                        string Pack;

                        //Instead of passing the values to the method, we take them out of the method after it's finished
                        userInterface.GetNewItemInformation(out ID, out Name, out Price, out Pack);

                        bool WineAddedBool = false;

                        while (WineAddedBool == false)
                        {
                            //Creates an instance of beverage that will be used to see if the ID the user wants to use already exists
                            Beverage IDCheck = beverageEntities.Beverages.Find(ID);

                            if (IDCheck == null)
                            {
                                //Create an instance of beverage to eventually add to the database
                                Beverage newWine = new Beverage();

                                newWine.id = ID;
                                newWine.name = Name;
                                newWine.pack = Pack;
                                newWine.price = Price;

                                beverageEntities.Beverages.Add(newWine);
                                WineAddedBool = true;
                            }
                            else
                            {
                                Console.WriteLine("Sorry, a wine with this ID already exists. Would you like to enter a new ID?");
                                Console.WriteLine("y/n?");
                                string input = "nothing";
                                while (input != "y")
                                {
                                    input = Console.ReadLine();
                                    if (input == "y")
                                    {
                                        ID = userInterface.GetNewID();
                                    }
                                    else if (input == "n")
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        Console.WriteLine("Sorry, you entered something other than a y or an n");
                                    }
                                }

                            }
                        }

                        break;

                    case 4:
                        //Delete an item from the list
                        string IDToDelete = userInterface.GetDeleteQuery();
                        Beverage deleteWine = beverageEntities.Beverages.Find(IDToDelete);

                        if(deleteWine != null)
                        {
                            beverageEntities.Beverages.Remove(deleteWine);
                            userInterface.DisplayDeleteSuccess();
                        }
                        else
                        {
                            Console.WriteLine("Error, the ID you entered does not corrospond to any Wine currently in the database.");
                        }
                        break;
                    case 5:
                        //Update an item from the database
                        string IDToUpdate = userInterface.GetUpdateQuery();
                        Beverage updateBeverage = beverageEntities.Beverages.Find(IDToUpdate);

                        if(updateBeverage != null)
                        {
                            Console.WriteLine("Would you like to change the ID of the wine?");
                            Console.WriteLine("y/n?");
                            string userInput = Console.ReadLine();
                            if(userInput == "y")
                            {
                                Console.WriteLine("What is the new ID you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.id = userInput;
                            }
                            Console.WriteLine("Would you like to change the name of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new name you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.name = userInput;
                            }
                            Console.WriteLine("Would you like to change the price of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new price you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.price = decimal.Parse(userInput);
                            }
                            Console.WriteLine("Would you like to change the pack of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new pack you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.pack = userInput;
                            }

                            userInterface.DisplayUpdateSuccess();
                        }
                        else
                        {
                            userInterface.DisplayUpdateFailure();
                        }
                        break;
                    case 6:

                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }

            beverageEntities.SaveChanges();
        }
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Import the database and show import message (This is done on startup by default)
            BeverageACullenEntities beverageACullenEntities = new BeverageACullenEntities();
            userInterface.DisplayImportSuccess();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                switch (choice)
                {
                    case 1:

                        //Display entire list of beverages
                        userInterface.DisplayAllItems(beverageACullenEntities);
                        break;

                    case 2:
                        //Search the list for a beverage by ID
                        string searchQuery = userInterface.GetSearchQuery();

                        Beverage searchBeverage = beverageACullenEntities.Beverages.Find(searchQuery);

                        if (searchBeverage != null)
                        {
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(searchBeverage);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 3:
                        //Add a beverage item to the list

                        //Get values from user
                        string[] addItemInfo = userInterface.GetItemInformation(false,"");

                        //Make sure the user entered ID is not already on the list
                        if (beverageACullenEntities.Beverages.Find(addItemInfo[0]) == null)
                        {
                            //Create a new beverage and import values from user input
                            Beverage addBeverage = new Beverage();
                            addBeverage.id = addItemInfo[0];
                            addBeverage.name = addItemInfo[1];
                            addBeverage.pack = addItemInfo[2];
                            addBeverage.price = Convert.ToDecimal(addItemInfo[3]);
                            addBeverage.active = Convert.ToBoolean(addItemInfo[4]);

                            //Add the beverage to the database
                            beverageACullenEntities.Beverages.Add(addBeverage);
                            beverageACullenEntities.SaveChanges();
                            userInterface.DisplayAddItemSuccess();
                            userInterface.DisplayItem(addBeverage);

                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }
                        break;

                    case 4:
                        //Update a beverage item in the database

                        //Get search item ID from user
                        string updateQuery = userInterface.GetSearchQuery();

                        //Find the item by its ID
                        Beverage updateBeverage = beverageACullenEntities.Beverages.Find(updateQuery);

                        //If found...
                        if (updateBeverage != null)
                        {
                            //Display the item and directions for user reference
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(updateBeverage);
                            userInterface.DisplayUpdateDirections();

                            //get updated values from user
                            string[] updateItemInfo = userInterface.GetItemInformation(true, updateBeverage.id);
                            updateBeverage.name = updateItemInfo[1];
                            updateBeverage.pack = updateItemInfo[2];
                            updateBeverage.price = Convert.ToDecimal(updateItemInfo[3]);
                            updateBeverage.active = Convert.ToBoolean(updateItemInfo[4]);

                            beverageACullenEntities.SaveChanges();

                            userInterface.DisplayUpdateSuccess();
                            userInterface.DisplayItem(updateBeverage);

                        }
                        else //if not found...
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 5:
                        //Delete beverage from database
                        string deleteQuery = userInterface.GetSearchQuery();
                        Beverage deleteBeverage = beverageACullenEntities.Beverages.Find(deleteQuery);

                        if (deleteBeverage != null)
                        {
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(deleteBeverage);

                            beverageACullenEntities.Beverages.Remove(deleteBeverage);
                            beverageACullenEntities.SaveChanges();

                            userInterface.DisplayDeleteMessage();

                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }