Exemple #1
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);
        }
Exemple #2
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);
        }