예제 #1
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);
        }
예제 #2
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();
        }
예제 #3
0
        internal static void EatCandy(CandyStorage db)
        {
            var candyNames   = db.GetCandyNames();
            var eatCandyMenu = new View()
                               .AddMenuText("Which candy do you want to eat?")
                               .AddMenuOptions(candyNames);

            Console.Write(eatCandyMenu.GetFullMenu());

            var candySelected = Console.ReadKey().KeyChar.ToString();
            var candyIndex    = int.Parse(candySelected);
            var candyToEat    = candyNames[candyIndex - 1];

            db.EatCandy(candyToEat);
        }