Ejemplo n.º 1
0
        public static void WaterAPlant()
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            var watering = true;

            while (watering)
            {
                var db = new GardenContext();
                ViewPlants();
                Console.WriteLine($"Please enter the number of the plant you would like to water.");
                var input        = Console.ReadLine();
                var waterPlantId = TryInt(input);
                var plantToWater = db.Plants.FirstOrDefault(p => p.Id == waterPlantId);
                if (plantToWater == null)
                {
                    Console.WriteLine($"That is not a valid selection. Please try again.");
                }
                else
                {
                    plantToWater.LastWateredDate = DateTime.Now;
                    watering = false;
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
        }
Ejemplo n.º 2
0
        public static void RemovePlant()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            var removing = true;

            while (removing)
            {
                var db = new GardenContext();
                ViewPlants();
                Console.WriteLine($"Please enter the number of the plant you would like to remove.");
                var input         = Console.ReadLine();
                var deletePlantId = TryInt(input);
                var plantToRemove = db.Plants.FirstOrDefault(p => p.Id == deletePlantId);
                if (plantToRemove == null)
                {
                    Console.WriteLine($"That is not a valid selection. Please try again.");
                }
                else
                {
                    db.Plants.Remove(plantToRemove);
                    removing = false;
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
        }
Ejemplo n.º 3
0
        public static void AddPlant()
        {
            var db = new GardenContext();

            Console.WriteLine($"What plant would you like to add? Please enter species.");
            var species = Console.ReadLine();

            Console.WriteLine($"Where is the {species} planted? Please enter a location.");
            var locationPlanted = Console.ReadLine();

            Console.WriteLine($"How much sunlight does this {species} need? Please enter a number.");
            var lightNeeded = double.Parse(Console.ReadLine());

            Console.WriteLine($"How much water does this {species} need? Please enter the recommended number of daily waterings.");
            var waterNeeded = double.Parse(Console.ReadLine());

            var plant = new Plant
            {
                Species         = species,
                LocatedPlanted  = locationPlanted,
                PlantedDate     = DateTime.Now,
                LastWateredDate = DateTime.Now,
                LightNeeded     = lightNeeded,
                WaterNeeded     = waterNeeded
            };

            db.Plants.Add(plant);
            db.SaveChanges();
        }
Ejemplo n.º 4
0
        public static void ViewPlants()
        {
            var db = new GardenContext();

            foreach (var p in db.Plants)
            {
                var displayPlants = db.Plants.OrderBy(p => p.LocatedPlanted);
                Console.WriteLine($"{p.Id} {p.Species} is planted in {p.LocatedPlanted}.");
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //create var to access methods in Gardener (UI)
            var garden = new Gardener();
            //create var to access db
            var db = new GardenContext();

            //welcome user to the Garden Database then call menu method
            Console.WriteLine($"Welcome to the Garden Database.");
            Console.WriteLine($"What would you like to do?");

            //set bool to keep menu/options running
            var isRunning = true;

            //start while loop
            while (isRunning)
            {
                var menuInt = garden.Menu();
                if (menuInt == 1)
                {
                    Gardener.ViewPlants();
                }
                else if (menuInt == 2)
                {
                    Gardener.AddPlant();
                }
                else if (menuInt == 3)
                {
                    Gardener.RemovePlant();
                }
                else if (menuInt == 4)
                {
                    Gardener.WaterAPlant();
                }
                else if (menuInt == 5)
                {
                    Gardener.ViewUnwatered();
                }
                else if (menuInt == 6)
                {
                    Gardener.LocationSummary();
                }
                else if (menuInt == 7)
                {
                    Console.WriteLine($"Thank you for using the Garden Database.");
                    Console.WriteLine($"Goodbye.");
                    Console.Clear();
                    isRunning = false;
                }
            }
        }
Ejemplo n.º 6
0
        public static void ViewUnwatered()
        {
            var db            = new GardenContext();
            var displayPlants = db.Plants.Where(p => p.LastWateredDate < DateTime.Today);

            if (displayPlants == null)
            {
                Console.WriteLine($"No plants have gone without water today.");
            }
            foreach (var d in displayPlants)
            {
                Console.WriteLine($"{d.Species} was last watered on {d.LastWateredDate}.");
            }
        }
Ejemplo n.º 7
0
        public static void LocationSummary()
        {
            var db            = new GardenContext();
            var displayPlants = db.Plants.Where(p => p.LocatedPlanted != "");

            if (displayPlants == null)
            {
                Console.WriteLine($"You have no plants in your garden.");
            }
            var allPlants = displayPlants.OrderBy(d => d.LocatedPlanted);

            foreach (var d in allPlants)
            {
                Console.WriteLine($"{d.Species} is planted in {d.LocatedPlanted}.");
            }
        }