예제 #1
0
        internal static void AddNewCandy(CandyStorage db, List <string> FlavorList)
        {
            Console.WriteLine("What is the name of your candy?");
            string Name = Console.ReadLine().ToString();

            Console.WriteLine("Who is the manufacturer of your candy?");
            string Manufacturer = Console.ReadLine().ToString();

            Console.WriteLine("Choose your candy flavor: ");
            foreach (string flavor in FlavorList)
            {
                Console.WriteLine(flavor);
            }

            string Flavor = Console.ReadLine().ToLower();

            Console.WriteLine("When did you buy this candy? [EX] 2010, 12, 23");
            Console.WriteLine("Enter Year:");
            int Year = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter Month:");
            int Month = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter Day:");
            int Day = Convert.ToInt32(Console.ReadLine());

            var DateReceived = new DateTime(Year, Month, Day);

            var newCandy = new Candy(Name, Manufacturer, Flavor, DateReceived);

            db.SaveNewCandy(newCandy);
            Console.WriteLine($"Now you own the candy {newCandy.Name}");
            Console.ReadKey();
        }
예제 #2
0
 private static void EatRandomCandy(CandyStorage db)
 {
     Console.WriteLine("Here is a list of flavors that are available:");
     db.PrintFlavorList();
     Console.WriteLine("Choose one flavor by typing it in and hitting enter to eat a random candy of that flavor!");
     db.FindRandomCandy();
 }
예제 #3
0
        private static bool TakeActions(CandyStorage db, ConsoleKeyInfo userInput, int userId, Users user)
        {
            Console.Write(Environment.NewLine);

            if (userInput.Key == ConsoleKey.Escape)
            {
                return(true);
            }

            var selection = userInput.KeyChar.ToString();

            switch (selection)
            {
            case "1":
                AddCandyMenu.AddCandyMenus(db, userId);
                break;

            case "2":
                EatCandyMenu.AddEatCandyMenu(db, userId);
                break;

            case "3":
                EatRandomCandyMenu.AddRandomCandyMenu(db, userId);
                break;

            case "4":
                TradeCandyMenu.AddTradeCandyMenu(db, userId, user, candyUsers);
                break;

            default: return(true);
            }
            return(false);
        }
예제 #4
0
        private static void EatRandomCandy(CandyStorage db)
        {
            var list = db.allTheDefaultCandies().OrderBy(x => x.DateReceived);

            Console.WriteLine("Here are your candies");

            foreach (var candy in list)
            {
                Console.WriteLine($"{candy.Name} : {candy.Manufacturer} : {candy.Flavor} : {candy.DateReceived}");
            }

            var candyList = db.allTheDefaultCandies();

            Console.WriteLine("Would you like to eat a random piece of candy based on flavor?");
            var    eatingCandyInput = Console.ReadLine();
            var    filterCandies    = candyList.Where(candy => candy.Flavor == eatingCandyInput).ToList();
            Random random           = new Random();
            int    randnum          = random.Next(0, filterCandies.Count);

            candyList.RemoveAt(randnum);

            var userInput = MainMenu();
            var exit      = false;

            exit = TakeActions(db, userInput);
        }
예제 #5
0
        internal static void AddNewCandy(CandyStorage db, List <CandyStorage> candyOwners)
        {
            var addMenu = new View();

            Console.Write(addMenu.GetFullMenu());
            Console.WriteLine("Might you know the name of the candy you wish to add?");
            var candyName = Console.ReadLine().ToString();

            Console.Write(addMenu.GetFullMenu());
            Console.WriteLine("And might you know the manufacturer's name of the candy you wish to add?");
            var candyManufacturer = Console.ReadLine().ToString();

            Console.Write(addMenu.GetFullMenu());
            Console.WriteLine("And might you know the flavor profile of the candy you wish to add?");
            var candyFlavor = Console.ReadLine().ToString();

            var newCandy = new Candy(candyName, candyFlavor, candyManufacturer);

            db.addCandy(newCandy);
            Console.Write(addMenu.GetFullMenu());
            Console.WriteLine($"Now you own the candy {newCandy.Name}.");
            Console.WriteLine();
            Console.WriteLine("Press enter to continue.");
            Console.ReadKey();
            var exit = false;

            while (!exit)
            {
                var userInput = MainMenu();
                exit = TakeActions(db, userInput, candyOwners);
            }
        }
예제 #6
0
        public static bool TakeActions(CandyStorage db, ConsoleKeyInfo userInput)
        {
            Console.Write(Environment.NewLine);

            if (userInput.Key == ConsoleKey.Escape)
            {
                return(true);
            }

            var selection = userInput.KeyChar.ToString();

            switch (selection)
            {
            case "1": PickUser(db);
                break;

            case "2": AddNewCandy(db);
                break;

            case "3": EatCandy(db);
                break;

            case "4": EatRandomCandy(db);
                break;

            default: return(true);
            }
            return(true);
        }
예제 #7
0
        internal static void AddNewCandy(CandyStorage db)
        {
            // Get candy type
            var candyTypes   = db.GetCandyTypes();
            var newCandyMenu = new View()
                               .AddMenuText("What type of candy did you get?")
                               .AddMenuOptions(candyTypes);

            Console.Write(newCandyMenu.GetFullMenu());

            var selectedCandyType = Console.ReadKey().KeyChar.ToString();
            var candyTypeIndex    = int.Parse(selectedCandyType);
            var candyType         = candyTypes[candyTypeIndex - 1];

            // Get candy name

            var candyNames    = db.GetCandyNames(candyType);
            var candyNameMenu = new View()
                                .AddMenuText("What is the name of the candy?")
                                .AddMenuOptions(candyNames)
                                .AddMenuText("Or enter a new name");

            Console.Write(candyNameMenu.GetFullMenu());

            int candyNameIndex;
            var candyName = Console.ReadLine();

            int.TryParse(candyName, out candyNameIndex);

            if (candyNameIndex > 0)
            {
                candyName = candyNames[candyNameIndex - 1];
            }

            // Get candy manufacturer
            var candyMakes    = db.GetCandyMakes();
            var candyMakeMenu = new View()
                                .AddMenuText("Who makes the candy?")
                                .AddMenuOptions(candyMakes)
                                .AddMenuText("Or enter a new manufacturer");

            Console.Write(candyMakeMenu.GetFullMenu());

            int candyMakeIndex;
            var candyMake = Console.ReadLine();

            int.TryParse(candyMake, out candyMakeIndex);

            if (candyMakeIndex > 0)
            {
                candyMake = candyMakes[candyMakeIndex - 1];
            }

            // Make new candy from inputs and save
            var candyToAdd = new Candy {
                Name = candyName, Flavor = candyType, Manufacturer = candyMake, ReceivedOn = DateTime.Now
            };

            db.SaveNewCandy(candyToAdd);
        }
예제 #8
0
        private static void TradeCandy(CandyStorage db)
        {
            var tradeCandyMenu = new View()
                                 .AddMenuText("Choose a trade request")
                                 .AddMenuOptions(otherUsers.Select(u => u.WantsToTrade()).ToList());

            Console.Write(tradeCandyMenu.GetFullMenu());

            var chosenUser  = Console.ReadKey().KeyChar.ToString();
            var chosenIndex = int.Parse(chosenUser);
            var otherUser   = otherUsers[chosenIndex - 1];

            var userCandyMenu = new View()
                                .AddMenuText($"Request a candy from {otherUser.Name}")
                                .AddMenuOptions(otherUser.Candies.Select(c => c.Name).ToList());

            Console.Write(userCandyMenu.GetFullMenu());

            var chosenCandy = Console.ReadKey().KeyChar.ToString();
            var candyIndex  = int.Parse(chosenCandy);
            var otherCandy  = otherUser.Candies[candyIndex - 1];

            var yourCandyMenu = new View()
                                .AddMenuText($"Which candy do you want to trade for {otherCandy.Name}?")
                                .AddMenuOptions(you.Candies.Select(c => c.Name).ToList());

            Console.Write(yourCandyMenu.GetFullMenu());

            var yourChosenCandy = Console.ReadKey().KeyChar.ToString();
            var yourIndex       = int.Parse(yourChosenCandy);
            var yourCandy       = you.Candies[yourIndex - 1];

            you.TradeCandy(otherCandy, you.Candies.FindIndex(c => c.Name == yourCandy.Name));
            otherUser.TradeCandy(yourCandy, otherUser.Candies.FindIndex(c => c.Name == otherCandy.Name));
        }
예제 #9
0
        internal static void AddNewCandy(CandyStorage db)
        {
            //  Candy Types  //
            var candyTypes        = db.GetCandyTypes();
            var newCandyMenuTypes = new View()
                                    .AddMenuText("What type of candy did you get?")
                                    .AddMenuOptions(candyTypes);

            Console.Write(newCandyMenuTypes.GetFullMenu());

            var selectedCandyType = Console.ReadKey();

            db.SaveNewCandy(selectedCandyType.Key, "CandyType");

            //  Candy Names //
            var candyNames        = db.GetCandyNames();
            var newCandyMenuNames = new View()
                                    .AddMenuText("What is the name of the candy?")
                                    .AddMenuOptions(candyNames);

            Console.Write(newCandyMenuNames.GetFullMenu());

            var selectedCandyName = Console.ReadKey();

            db.SaveNewCandy(selectedCandyName.Key, "CandyName");

            //  Candy Manufacturers  //
            var candyManufacturers        = db.GetCandyManufacturers();
            var newCandyMenuManufacturers = new View()
                                            .AddMenuText("Who made the candy?")
                                            .AddMenuOptions(candyManufacturers);

            Console.Write(newCandyMenuManufacturers.GetFullMenu());

            var selectedCandyManufacturer = Console.ReadKey();

            db.SaveNewCandy(selectedCandyManufacturer.Key, "CandyManuf");

            //  Candy Flavors  //
            var candyFlavors       = db.GetFlavorCategories();
            var newCandyMenuFlavor = new View()
                                     .AddMenuText("What flavor is the candy?")
                                     .AddMenuOptions(candyFlavors);

            Console.Write(newCandyMenuFlavor.GetFullMenu());

            var selectedCandyFlavor = Console.ReadKey();

            db.SaveNewCandy(selectedCandyFlavor.Key, "CandyFlavor");

            //  Candy Acquired Date  //
            var newCandyMenuDateAcquired = new View()
                                           .AddMenuText("When did you acquire the candy? MM/DD/YYYY");

            Console.Write(newCandyMenuDateAcquired.GetFullMenu());
            var dateOfAcquisition = Console.ReadLine();

            db.SetCandyAcquisitionDate(dateOfAcquisition);
            db.PersistNewCandyObject();
        }
예제 #10
0
        internal static void EatSomeCandy()
        {
            var db = new CandyStorage();
            var currentCandyInventory = db.ReturnCandyInventory();

            if (currentCandyInventory.Count < 1)
            {
                var eatCandy = new View()
                               .AddMenuText("You have no candy");
                Console.Write(eatCandy.GetFullMenu());
                Console.ReadKey();
            }
            else
            {
                var viewCandy = new View()
                                .AddMenuText("Here is your candy inventory:");
                Console.Write(viewCandy.GetFullMenu());
                for (int i = 0; i < currentCandyInventory.Count; i++)
                {
                    Console.WriteLine("");
                    Console.WriteLine("         Candy Name: " + currentCandyInventory[i].Name);
                    Console.WriteLine("         Candy Type: " + currentCandyInventory[i].CandyType);
                    Console.WriteLine(" Candy Manufacturer: " + currentCandyInventory[i].Manufacturer);
                    Console.WriteLine("       Candy Flavor: " + currentCandyInventory[i].FlavorCategory);
                    Console.WriteLine("Candy Date Received: " + currentCandyInventory[i].DateReceived);
                }
                Console.WriteLine("");
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
            }
        }
예제 #11
0
        public static void PickUser(CandyStorage db)
        {
            var users = db.allTheUsers();

            Console.WriteLine("Here are your users");

            foreach (var user in users)
            {
                Console.WriteLine($"{user.userName}");
            }
            Console.ReadLine();

            Console.WriteLine("Which user would you like to use?:");
            var userChoice = Console.ReadLine();
            var userIfound = users.Where(user => user.userName == userChoice).Single();

            Console.WriteLine($"Here are the candies for {userChoice}: ");

            var candies = db.getOwnersCandy(userIfound.Id);

            foreach (var candy in candies)
            {
                Console.WriteLine($"{candy.Name}");
            }

            Console.ReadLine();

            var userInput = MainMenu();
            var exit      = false;

            exit = TakeActions(db, userInput);
        }
예제 #12
0
        private static bool TakeActions(CandyStorage db, ConsoleKeyInfo userInput, List <CandyStorage> candyOwners)
        {
            Console.Write(Environment.NewLine);

            if (userInput.Key == ConsoleKey.Escape)
            {
                return(true);
            }

            var selection = userInput.KeyChar.ToString();

            switch (selection)
            {
            case "1": AddNewCandy(db, candyOwners);
                break;

            case "2": EatCandyByFlavor(db, candyOwners);
                break;

            case "3": EatCandy(db, candyOwners);
                break;

            case "4": TradeCandy(db, candyOwners);
                break;

            default: return(true);
            }
            return(true);
        }
예제 #13
0
        internal static void RemoveCandy(Candy candy, CandyStorage db, List <CandyStorage> candyOwners)
        {
            var theCandy = db.Candies;

            theCandy.Remove(candy);

            Console.WriteLine();
            Console.WriteLine("You have these candies left:");

            foreach (var c in theCandy)
            {
                Console.WriteLine($"{c.Name} acquired {c.Date}.");
            }

            Console.WriteLine();
            Console.WriteLine("Hit enter to continue.");
            Console.ReadKey();

            var exit = false;

            while (!exit)
            {
                var userInput = MainMenu();
                exit = TakeActions(db, userInput, candyOwners);
            }
        }
예제 #14
0
        private static void EatCandy(CandyStorage db)
        {
            var list             = db.allTheDefaultCandies().OrderBy(x => x.DateReceived);
            var defaultCandyList = db.allTheDefaultCandies().OrderBy(y => y.DateReceived);

            Console.WriteLine("Here are your candies");

            foreach (var defaultCandy in defaultCandyList)
            {
                Console.WriteLine($"{defaultCandy.Name} : {defaultCandy.Manufacturer} : {defaultCandy.Flavor} : {defaultCandy.DateReceived}");
            }

            foreach (var candy in list)
            {
                Console.WriteLine($"{candy.Name} : {candy.Manufacturer} : {candy.Flavor} : {candy.DateReceived}");
            }

            var candyList = db.allTheDefaultCandies();

            Console.WriteLine("Would you like to eat a piece of candy?");
            var eatingCandyInput = Console.ReadLine();
            var filterCandies    = candyList.Where(candy => candy.Name == eatingCandyInput).ToList();
            var eatingCandy      = filterCandies.Single();

            candyList.Remove(eatingCandy);

            var userInput = MainMenu();
            var exit      = false;

            exit = TakeActions(db, userInput);
        }
예제 #15
0
        internal static void AddNewCandy(CandyStorage db)
        {
            Console.WriteLine($"Candy Name:");
            var candyName = Console.ReadLine();

            Console.WriteLine($"Manufacturer:");
            var candyManufacturer = Console.ReadLine();

            Console.WriteLine($"Flavor:");
            var flavorCrap = Console.ReadLine();

            Console.WriteLine($"Date: {DateTime.Now}");
            var candyDateReceived = DateTime.Now.ToString();

            var newCandy = new Candy
            {
                Name         = candyName,
                Manufacturer = candyManufacturer,
                Flavor       = flavorCrap,
                DateReceived = candyDateReceived,
            };

            db.SaveNewCandy(newCandy);

            Console.WriteLine("Your Candy: ");
            Console.WriteLine($"{newCandy.Name} : {newCandy.Manufacturer} : {newCandy.Flavor} : {newCandy.DateReceived}");
            Console.ReadLine();

            var userInput = MainMenu();
            var exit      = false;

            exit = TakeActions(db, userInput);
        }
예제 #16
0
 private static void EatCandy(CandyStorage db)
 {
     Console.WriteLine("Here is a list to choose candy to eat :");
     db.PrintList();
     Console.WriteLine("Choose just ONE candy by typing it in and hitting enter to EAT!");
     db.FindCandy();
 }
예제 #17
0
 private static void NewTrade(CandyStorage db)
 {
     Console.WriteLine("Enter your name and hit Enter");
     myName = Console.ReadLine();
     Console.WriteLine("Enter your id and hit Enter");
     myId = int.Parse(Console.ReadLine());
 }
예제 #18
0
 private static void TradeCandy(CandyStorage db)
 {
     Console.WriteLine("Here are candy owners you can trade with.");
     // db.PrintOwnersList();
     db.MatchCandyId();
     Console.WriteLine("Hit Enter to go back to the menu!");
 }
예제 #19
0
        static List <Candy> filterCandy(string candyFlavor, CandyStorage db)
        {
            var candyList         = db.ShowList();
            var filteredCandyList = candyList.FindAll(candy => candy.Flavor == candyFlavor);

            return(filteredCandyList);
        }
예제 #20
0
        private static bool TakeActions(CandyStorage db, ConsoleKeyInfo userInput, List <string> FlavorList, Users users)
        {
            Console.Write(Environment.NewLine);

            if (userInput.Key == ConsoleKey.Escape)
            {
                return(true);
            }

            var selection = userInput.KeyChar.ToString();

            switch (selection)
            {
            case "1": AddNewCandy(db, FlavorList);
                return(false);

            case "2": EatCandy(db);
                return(false);

            case "3": EatRandomCandy(db, FlavorList);
                return(false);

            case "4": TradeCandy(users);
                return(false);

            case "5": ListCandy(db);
                return(false);

            default: return(false);
            }
        }
예제 #21
0
 private static void ListOfCandy(CandyStorage db)
 {
     Console.WriteLine("Here is your list of current candies in inventory");
     foreach (Candy candy in db._myCandy)
     {
         Console.WriteLine($"Candy : {candy.Name}        Flavor : {candy.Flavor}");
     }
     Console.ReadLine();
 }
예제 #22
0
 private static void ListCandy(CandyStorage db)
 {
     foreach (var candy in db.ShowList())
     {
         Console.Write($"\t{candy.Name}\n");
     }
     Console.WriteLine("\nPress any key to return to the main menu");
     Console.ReadKey();
 }
예제 #23
0
        internal static CandyStorage SetupNewApp()
        {
            Console.Title = "Cross Confectioneries Incorporated";

            var db = new CandyStorage();

            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            return(db);
        }
예제 #24
0
        internal static void DisplayCandyNames(CandyStorage db)
        {
            var candyName     = db.GetNames();
            var candyNameMenu = new View()
                                .AddMenuText("Select from the following:")
                                .AddMenuOptions(candyName);

            Console.Write(candyNameMenu.GetFullMenu());
            Console.ReadKey();
        }
예제 #25
0
        internal static CandyStorage SetupNewApp(string ownerName)
        {
            Console.Title           = "Cross Confectioneries Incorporated";
            Console.BackgroundColor = ConsoleColor.DarkMagenta;
            Console.ForegroundColor = ConsoleColor.Cyan;

            var db = new CandyStorage(ownerName);

            return(db);
        }
예제 #26
0
        internal static void AddNewCandy(CandyStorage db)
        {
            var newCandy = new Candy
            {
                Name = "Whatchamacallit"
            };

            var savedCandy = db.SaveNewCandy(newCandy);

            Console.WriteLine($"Now you own the candy {savedCandy.Name}");
        }
예제 #27
0
        private static void EatCandy(CandyStorage db, List <CandyStorage> candyOwners)

        {
            var           theCandy   = db.Candies;
            List <string> candyNames = new List <string>();
            var           candyMenu  = new View();

            foreach (var candy in theCandy)
            {
                if (candyNames.Contains(candy.Name) == false)
                {
                    candyNames.Add(candy.Name);
                }
            }

            foreach (var name in candyNames)
            {
                candyMenu.AddMenuOption(name);
            }

            Console.Write(candyMenu.GetFullMenu());

            Console.WriteLine();
            Console.WriteLine("Please select the candy you would like to eat.");

            var flavorMenuInput  = Console.ReadKey();
            var chosenNameNumber = int.Parse(flavorMenuInput.KeyChar.ToString());

            var filteredCandy = theCandy.Where(c => c.Name.Contains(candyNames[chosenNameNumber - 1]))
                                .ToList();

            var oldestCandy = filteredCandy.OrderBy(c => c.Date).First();

            RemoveCandy(oldestCandy, db, candyOwners);

            //Console.WriteLine();
            //Console.WriteLine("You have these candies left:");

            //foreach (var candy in theCandy)
            //{
            //    Console.WriteLine($"{candy.Name} acquired {candy.Date}.");
            //}

            //Console.WriteLine();
            //Console.WriteLine("Hit enter to continue.");
            //Console.ReadKey();

            //var exit = false;
            //while (!exit)
            //{
            //    var userInput = MainMenu();
            //    exit = TakeActions(db, userInput, candyOwners);
            //}
        }
예제 #28
0
        internal static ConsoleKeyInfo MainMenu(CandyStorage db)
        {
            View mainMenu = new View()
                            .AddMenuOption("Did you just get some new candy? Add it here.")
                            .AddMenuOption("Do you want to eat some candy? Take it here.")
                            .AddMenuText("Press 0 to exit.");

            Console.Write(mainMenu.GetFullMenu());
            var userOption = Console.ReadKey();

            return(userOption);
        }
예제 #29
0
        internal static ConsoleKeyInfo MainMenu(CandyStorage db)
        {
            View mainMenu = new View()
                            .AddMenuOption("Add new candy")
                            .AddMenuOption("Eat candy")
                            .AddMenuText("Press 0 to exit.");

            Console.Write(mainMenu.GetFullMenu());
            var userOption = Console.ReadKey();

            return(userOption);
        }
예제 #30
0
        internal static void AddNewCandy(CandyStorage db)
        {
            var candyTypes   = db.GetCandyTypes();
            var newCandyMenu = new View()
                               .AddMenuText("What type of candy did you get?")
                               .AddMenuOptions(candyTypes);

            Console.Write(newCandyMenu.GetFullMenu());

            var selectedCandyType = Console.ReadKey();

            db.SaveNewCandy(selectedCandyType.Key);
        }