static void Main(string[] args) { //Create an instance of the UserInterface class UserInterface userInterface = new UserInterface(); //Create an instance of the WineItemCollection class WineItemCollection wineItemCollection = new WineItemCollection(); //Display the Welcome Message to the user userInterface.DisplayWelcomeGreeting(); Console.BufferHeight = 5000; Console.BufferWidth = 150; //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 != 7) { switch (choice) { case 1: userInterface.DisplayImportSuccess(); break; case 2: //Print Entire List Of Items string[] allItems = wineItemCollection.GetPrintStringsForAllItems(); if (allItems.Length > 0) { //Display all of the items userInterface.DisplayAllItems(allItems); } else { //Display error message for all items userInterface.DisplayAllItemsError(); } break; case 3: //Search For An Item string searchQuery = userInterface.GetSearchQuery(); string itemInformation = wineItemCollection.FindById(searchQuery); if (itemInformation != null) { userInterface.DisplayItemFound(itemInformation); } else { userInterface.DisplayItemFoundError(); } break; case 4: // Add A New Item To The List string[] newItemInformation = userInterface.GetItemInformation(); // Convert the price to a decimal: decimal price = Convert.ToDecimal(newItemInformation[3]); // Set a boolean to hold whether the item is active: bool active = false; // If the input was Y for yes, set active to true: if (newItemInformation[4] == "Y") { active = true; } // Send info to WineItemCollection to add a new item: if (wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], price, active)) { userInterface.DisplayAddWineItemSuccess(); } else { userInterface.DisplayItemAlreadyExistsError(); } break; case 5: // Update an item in the list: string idUpdate = userInterface.GetUpdateId(); if (wineItemCollection.UpdateBeverageItem(idUpdate)) { userInterface.DisplayItemUpdateSuccess(); } else { userInterface.DisplayItemUpdateError(); } break; case 6: // Delete an item from the list: string idDelete = userInterface.GetDeleteId(); if (wineItemCollection.DeleteBeverageItem(idDelete)) { userInterface.DisplayItemDeleteSuccess(); } else { userInterface.DisplayItemDeleteError(); } break; } //Get the new choice of what to do from the user choice = userInterface.DisplayMenuAndGetResponse(); } }
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(); } }