Example #1
0
        public void RemovePlant(int plantId)
        {
            var db      = new PlantContext();
            var validId = db.Plants.Any(plant => plant.Id == plantId);

            while (validId != true)
            {
                Console.WriteLine("That is not a valid Id number please try again");
                plantId = int.Parse(Console.ReadLine());
                validId = db.Plants.Any(plant => plant.Id == plantId);
            }
            if (validId == true)
            {
                var idToRemove = db.Plants.FirstOrDefault(plant => plant.Id == plantId);
                Console.WriteLine($"Are you sure you wand to remove {idToRemove.Species} with an Id of {idToRemove.Id}? (Y)/(N)");
                var confirmRemoval = Console.ReadLine().ToLower();
                while (confirmRemoval != "y" && confirmRemoval != "n")
                {
                    Console.WriteLine("Please take this seriously we're about to delete a plant. Input (Y) or (N) ");
                    confirmRemoval = Console.ReadLine().ToLower();
                }
                if (confirmRemoval == "y")
                {
                    Console.WriteLine($"{idToRemove.Id} has been removed.");
                    db.Remove(idToRemove);
                    db.SaveChanges();
                }
                else
                {
                    Console.WriteLine("Nothing has been removed.");
                }
            }
        }
Example #2
0
        public void PlantNewPlant(string species, string locatedPlant, DateTime plantedDAte, DateTime lastWateredDate, double waterNeeded, double lightNeeded)
        {
            //interacts with
            var db       = new PlantContext();
            var newPlant = new Plant
            {
                Species         = species,
                LocatedPlant    = locatedPlant,
                PlantedDate     = plantedDAte,
                LastWateredDate = lastWateredDate,
                WaterNeeded     = waterNeeded,
                LightNeeded     = lightNeeded
            };

            db.Plants.Add(newPlant);
            db.SaveChanges();
            Console.WriteLine($"You have added {species} to the Plant Database one {DateTime.Now} ");
        }
Example #3
0
        public void WaterPlant(int plantId)
        {
            var db      = new PlantContext();
            var validId = db.Plants.Any(plant => plant.Id == plantId);

            while (validId != true)
            {
                Console.WriteLine("That is not a valid Id number please try again");
                plantId = int.Parse(Console.ReadLine());
                validId = db.Plants.Any(plant => plant.Id == plantId);
            }
            if (validId == true)
            {
                var idToWater = db.Plants.FirstOrDefault(plant => plant.Id == plantId);
                idToWater.LastWateredDate = DateTime.Now;
                db.SaveChanges();
                Console.WriteLine($"{idToWater.Species} with a Id of {idToWater.Id} was watered on {idToWater.LastWateredDate}");
            }
        }