Exemple #1
0
        public void PullAPlant()
        {
            var db = new PlantContext();

            Console.WriteLine("What plant would you like to remove");
            var kind = Console.ReadLine().ToLower();

            // find the plant
            var photosythesisor = new Plant
            {
                Species = kind
            };
            var plantToPull = db.Plants.Where(p => p.Species == kind);

            // attempted check for repeated plants
            // if (kind.Count() > 1)
            // {
            //   var plantLineUp = db.Plants.Where(p => p.Species == kind);
            //   Console.WriteLine($"We found multiple {kind}. Which do you want to remove?");
            // foreach (var plant in plantLineUp)
            //   {
            //     var stackedPlant = plantLineUp[i];
            //     Console.WriteLine($"{i + 1}: {stackedPlant.PlantedDate}");

            //   }
            //   var index = int.Parse(Console.ReadLine());
            //   db.Plants.RemoveRange(plantLineUp[index - 1]);

            // }
            Console.WriteLine($"We've removed {kind} from the garden.");

            db.Plants.RemoveRange(plantToPull);
            db.SaveChanges();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var db        = new PlantContext();
            var work      = new GardenMaster();
            var isRunning = true;

            Console.WriteLine("Welcome to the garden! Please (select) an option");
            // Options
            while (isRunning == true)
            {
                Console.WriteLine("(VIEW) all plants");
                Console.WriteLine("(ADD) a plant");
                Console.WriteLine("(REMOVE) a plant");
                Console.WriteLine("(WATER) a plant");
                Console.WriteLine("(LOG) view the water log to find which plants need watering");
                Console.WriteLine("(YARD) view a summary of plant locations");
                Console.WriteLine("(QUIT) close this program");
                var input = Console.ReadLine().ToLower();
                // Methods adding plants
                if (input == "add")
                {
                    work.DigAHole();
                }
                else if (input == "remove")
                {
                    work.PullAPlant();
                }
                else if (input == "view")
                {
                    work.SeeTheFlowers();
                }
                else if (input == "water")
                {
                    work.MakeItRain();
                }
                else if (input == "log")
                {
                    work.SeeThirstyBoys();
                }
                else if (input == "yard")
                {
                    work.MilkshakesInTheYard();
                }

                else if (input == "quit")
                {
                    isRunning = false;
                    Console.WriteLine("Goodbye!");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("I'm sorry, I couldn't understand. Please try again.");
                }
            }
        }
Exemple #3
0
        public void SeeTheFlowers()
        {
            var db        = new PlantContext();
            var allPlants = db.Plants;

            foreach (var plant in allPlants)
            {
                Console.WriteLine($"Plant type: {plant.Species}, Yard: {plant.PlantLocation}, When Planted:{plant.PlanetedDate}, Light Rrequirements: {plant.LightLevelNeeded}, Cups of Water Needed / Day: {plant.WaterNeeded}");
            }
        }
Exemple #4
0
        public void SeeThirstyBoys()
        {
            var db = new PlantContext();
            // var dayOfWatering = new DateTime();
            var someThirstyBoys = db.Plants.OrderBy(plant => plant.LastWateredDate);

            foreach (var plant in someThirstyBoys)
            // if
            {
                Console.WriteLine($"{plant.Species} was last watered at {plant.LastWateredDate}");
            }
        }
Exemple #5
0
        public void DigAHole()
        {
            var db = new PlantContext();

            Console.WriteLine("What kind of plant would you like to add?");
            var kind = Console.ReadLine().ToLower();

            Console.WriteLine("What yard do you want to put it in?");
            Console.WriteLine("(NORTH) (SOUTH) (EAST) (WEST)");
            var home = Console.ReadLine().ToLower();

            var where = "";
            // Where is home for the plant
            if (home == "north")
            {
                where = "north";
            }
            else if (home == "south")
            {
                where = "south";
            }
            else if (home == "east")
            {
                where = "east";
            }
            else if (home == "west")
            {
                where = "west";
            }

            var creationTime = DateTime.Now;

            Console.WriteLine($"What level of light will {kind} need, on a scale of (1 = low) to (10 = high)?");
            var sunJuice = int.Parse(Console.ReadLine().ToLower());

            Console.WriteLine($"How much water will {kind} need, on a scale of (1 = low) to (10 = high)?");
            var electrolytes = int.Parse(Console.ReadLine().ToLower());

            // sum up and save to the plant db
            var photosythesisor = new Plant
            {
                Species          = kind,
                PlantLocation    = where,
                PlanetedDate     = creationTime,
                LightLevelNeeded = sunJuice,
                WaterNeeded      = electrolytes,
                LastWateredDate  = DateTime.Now,
            };

            db.Plants.Add(photosythesisor);
            db.SaveChanges();
        }
Exemple #6
0
        public void MakeItRain()
        {
            var db = new PlantContext();

            Console.WriteLine("What plant would you like to water");
            var kind = Console.ReadLine().ToLower();

            // find the plant
            var photosythesisor = new Plant
            {
                Species         = kind,
                LastWateredDate = DateTime.Now
            };
            var plantToUpdate = db.Plants.First(p => p.Species == kind);

            plantToUpdate.LastWateredDate = DateTime.Now;

            db.SaveChanges();
        }
Exemple #7
0
        public void MilkshakesInTheYard()
        {
            var db        = new PlantContext();
            var allPlants = db.Plants;

            Console.WriteLine("Please (select) a yard to view");
            Console.WriteLine("(NORTH) (SOUTH) (EAST) (WEST)");
            var home        = Console.ReadLine().ToLower();
            var northPlants = db.Plants.Where(plant => plant.PlantLocation == "north");
            var southPlants = db.Plants.Where(plant => plant.PlantLocation == "south");
            var eastPlants  = db.Plants.Where(plant => plant.PlantLocation == "east");
            var westPlants  = db.Plants.Where(plant => plant.PlantLocation == "west");

            if (home == "north")
            {
                foreach (var plant in northPlants)
                {
                    Console.WriteLine($"{plant.Species} is located in the {home} yard.");
                }
            }
            else if (home == "south")
            {
                foreach (var plant in southPlants)
                {
                    Console.WriteLine($"{plant.Species} is located in the {home} yard.");
                }
            }
            else if (home == "east")
            {
                foreach (var plant in eastPlants)
                {
                    Console.WriteLine($"{plant.Species} is located in the {home} yard.");
                }
            }
            else if (home == "west")
            {
                foreach (var plant in westPlants)
                {
                    Console.WriteLine($"{plant.Species} is located in the {home} yard.");
                }
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            {
                var isRunning = true;
                while (isRunning)
                {
                    var db       = new PlantContext();
                    var newPlant = new Plant();
                    Console.WriteLine("welcome to the garden!");
                    Console.WriteLine("would you like to (A)dd a plant, (R)emove a plant, or (U)pdate a plant?");
                    var input = Console.ReadLine().ToLower();

                    if (input == "a")
                    {
                        Console.WriteLine($"plant species?");
                        newPlant.Species = Console.ReadLine();
                        Console.WriteLine($"Where is your plant located?");
                        newPlant.LocatedPlanted = Console.ReadLine();
                        Console.WriteLine($"how much light does your plant need?");
                        newPlant.LightNeeded = Console.ReadLine();
                        Console.WriteLine("how often does your plant need to be watered?");
                        newPlant.WaterNeeded     = Console.ReadLine();
                        newPlant.LastWateredDate = DateTime.Now;
                        newPlant.PlantDate       = DateTime.Now;
                        db.plants.Add(newPlant);
                        db.SaveChanges();
                    }
                    else if (input == "r")
                    {
                        Console.WriteLine("Which plant would you like to delete?");
                        var plantToDelete = Console.ReadLine();

                        var toDelete = db.plants.FirstOrDefault(p => p.Species == plantToDelete);

                        if (toDelete != null)
                        {
                            db.plants.Remove(toDelete);
                            db.SaveChanges();
                        }
                        else
                        {
                            Console.WriteLine("Plant not found.");
                        }
                    }
                    // else if (input == "u") ;
                    // {
                    //   Console.WriteLine("Which plant would you like to update?");

                    //   var plantToUpdate = Console.ReadLine();

                    //   var toUpdate = db.plants.FirstOrDefault(p => p.Species == plantToUpdate);
                    //   if (toUpdate != null)
                    //   {
                    //     db.plants.Remove(toUpdate);
                    //     db.SaveChanges();
                    //   }
                    //   else
                    //   {
                    //     Console.WriteLine("Plant not found.");
                    //   }

                    //   Console.WriteLine($"what would you like to change about this plant? The (water) it needs, or how much (light) this plant needs?");

                    //   var update = Console.ReadLine().ToLower;

                    // if (update == "water")
                    // {
                    //   Console.WriteLine($"how much water does {plantToUpdate} need?");
                    //   var waterNeed = Console.ReadLine();
                    //   toUpdate.WaterNeeded = waterNeed;
                    //   db.plants.Update(toUpdate);
                    // }
                    // if (update == "light")
                    // {
                    //   Console.WriteLine($"how much water does {plantToUpdate} need?");
                    //   var lightNeed = Console.ReadLine();
                    //   toUpdate.LightNeeded = lightNeed;
                    //   db.plants.Update(toUpdate);
                    // }
                    // db.SaveChanges();
                    // var displayAll = db.plants.OrderBy(P => P.LastWateredDate);
                    // foreach (var Plant in displayAll)
                    // {
                    //   Console.WriteLine($"{Plant.Id}: {Plant.Species} was last watered on {Plant.LastWateredDate}.");
                    // }
                    // Console.WriteLine("What plant would you like to water? Please enter the plant id from the list above!");
                    // var userWater = Console.ReadLine().ToLower;
                    // var plantToWater = db.plants.FirstOrDefault(Plant => Plant.Id == userWater);
                    // plantToWater.LastWateredDate = DateTime.Now;
                    // db.SaveChanges();
                    Console.WriteLine("Would you like to plant another plant?");
                    var whileLoop = Console.WriteLine();
                    if (whileLoop == "yes")
                    {
                        isRunning = true;
                    }
                    else if (whileLoop == "no")
                    {
                        isRunning = false;
                    }
                }
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            // define isRunning variable
            var isRunning = true;
            // DEFINE ERROR MESSAGE
            var errorMessage = "Not a valid input, please try again";
            // CONNECT TO THE PLANT DATABASE
            var db = new PlantContext();

            // GREET USER
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.WriteLine("It's good to see you, fellow plant enthusiast!");
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            // Add space
            Console.WriteLine();
            while (isRunning)
            {
                // ASK WHAT THEY WOULD LIKE TO DO, PROVIDE OPTIONS
                Console.WriteLine("What would you like to do today?");
                Console.WriteLine("------------------------------------");
                Console.WriteLine("(VIEW 'v') all plants, (PLANT 'p') a plant, (REMOVE 'r') a plant, (WATER 'w') a plant, ");
                Console.WriteLine("(VIEW 'n') plants not watered today, (VIEW 'x') plants that need water, (LOCATION 'l') summary, or (QUIT 'q')");
                // GET USER INPUT AND CREATE SWITCH STATEMENT FOR OPTIONS ABOVE
                var input = Console.ReadLine().ToLower();
                // Add space
                Console.WriteLine();

                switch (input)
                {
                // * * * * * VIEW * * * * *
                case "v":
                    // VIEW ALL PLANTS IN DATABASE
                    var plants = db.Plants.OrderBy(p => p.LocatedPlant);
                    foreach (var p in plants)
                    {
                        Console.WriteLine("-----------------------------------------------------------");
                        Console.WriteLine($"Primary Key: {p.Id}");
                        Console.WriteLine($"Species: {p.Species}");
                        Console.WriteLine($"Location of plant: {p.LocatedPlant}");
                        Console.WriteLine($"Date planted: {p.PlantedDate.ToString("MMMM dd, yyyy")}.");
                        Console.WriteLine($"Last time plant was watered: {p.LastWateredDate.ToString("MMMM dd, yyyy")}.");
                        Console.WriteLine($"How many hours of sunlight needed per day: {p.LightNeeded}.");
                        Console.WriteLine($"How many milliliters of water needed per day: {p.WaterNeeded}.");
                        Console.WriteLine("-----------------------------------------------------------");
                    }
                    break;

                // * * * * * PLANT * * * * *
                case "p":
                    // PROMPT USER WITH QUESTIONS ABOUT THE PLANT
                    Console.WriteLine("What type of species is the plant?");
                    var species = Console.ReadLine().ToLower();
                    // Add space
                    System.Console.WriteLine();
                    Console.WriteLine("Where did you find the plant?");
                    var location = Console.ReadLine().ToLower();
                    // Add space
                    System.Console.WriteLine();
                    Console.WriteLine("When was the plant planted?");
                    DateTime plantedDate;
                    var      isValidDate = DateTime.TryParse(Console.ReadLine(), out plantedDate);
                    // Validate planted date
                    while (!isValidDate)
                    {
                        Console.WriteLine(errorMessage);
                        DateTime.TryParse(Console.ReadLine(), out plantedDate);
                    }
                    // Add space
                    System.Console.WriteLine();

                    Console.WriteLine("When was the last time the plant was watered?");
                    DateTime lastWateredDate;
                    isValidDate = DateTime.TryParse(Console.ReadLine(), out lastWateredDate);
                    // validate last watered date
                    while (!isValidDate)
                    {
                        Console.WriteLine(errorMessage);
                        DateTime.TryParse(Console.ReadLine(), out lastWateredDate);
                    }
                    // Add space
                    System.Console.WriteLine();

                    Console.WriteLine("How much sunlight is needed for this plant (hours per day)?");
                    double sunlightNeeded;
                    var    isDouble = double.TryParse(Console.ReadLine(), out sunlightNeeded);
                    // validate sunlight needed
                    while (!isDouble)
                    {
                        Console.WriteLine(errorMessage);
                        double.TryParse(Console.ReadLine(), out sunlightNeeded);
                    }
                    // Add space
                    System.Console.WriteLine();
                    Console.WriteLine("How much water is needed for this plant (in ml per day)?");
                    double waterNeeded;
                    isDouble = double.TryParse(Console.ReadLine(), out waterNeeded);
                    // validate water needed
                    while (!isDouble)
                    {
                        Console.WriteLine(errorMessage);
                        double.TryParse(Console.ReadLine(), out waterNeeded);
                    }
                    // Add space
                    System.Console.WriteLine();

                    // Fill in the plant properties with the input provided above
                    var plant = new Plant()
                    {
                        Species         = species,
                        LocatedPlant    = location,
                        PlantedDate     = plantedDate,
                        LastWateredDate = lastWateredDate,
                        // WateringFrequency = DateTime.Today - lastWateredDate,
                        LightNeeded = sunlightNeeded,
                        WaterNeeded = waterNeeded
                    };
                    // Add plant to the database
                    db.Plants.Add(plant);
                    // Save changes
                    db.SaveChanges();
                    break;

                // * * * * * REMOVE PLANT * * * * *
                case "r":
                    // Ask which user what plant they would like to remove
                    Console.WriteLine("Which plant would you like to remove from the database? Please select the ID.");
                    // Get user input
                    int removePlantID;
                    // Parse to int
                    var isInteger = int.TryParse(Console.ReadLine(), out removePlantID);
                    // Check to see if ID is in database
                    var isInDB = db.Plants.Any(p => p.Id == removePlantID);

                    // validate: check if not an integer or not in the database
                    while (!isInteger || !isInDB)
                    {
                        if (!isInteger)
                        {
                            // Add space
                            Console.WriteLine();
                            System.Console.WriteLine("Not a valid integer");
                        }
                        else if (!isInDB)
                        {
                            // Add space
                            Console.WriteLine();
                            System.Console.WriteLine("That value is not in the database");
                        }
                        // Add space
                        Console.WriteLine();
                        // Prompt user again
                        isInteger = int.TryParse(Console.ReadLine(), out removePlantID);
                        isInDB    = db.Plants.Any(p => p.Id == removePlantID);
                    }
                    // Set the first instance of the removeplantid where it is equal to that ID in the database to a variable
                    var removePlant = db.Plants.First(p => p.Id == removePlantID);
                    // Remove the plant that the user chose
                    db.Plants.Remove(removePlant);
                    db.SaveChanges();
                    break;

                // * * * * * WATER PLANT * * * * *
                case "w":
                    // Add space
                    Console.WriteLine();
                    // Ask user which plant they would like to water
                    Console.WriteLine("Which plant would you like to water? Please select the ID.");
                    // Get user input
                    int waterPlantID;
                    // Parse to int
                    isInteger = int.TryParse(Console.ReadLine(), out waterPlantID);
                    // Check to see if ID is in database
                    isInDB = db.Plants.Any(p => p.Id == waterPlantID);

                    // validate: check if not an integer or not in the database
                    while (!isInteger || !isInDB)
                    {
                        if (!isInteger)
                        {
                            // Add space
                            Console.WriteLine();
                            System.Console.WriteLine("Not a valid integer");
                        }
                        else if (!isInDB)
                        {
                            // Add space
                            Console.WriteLine();
                            System.Console.WriteLine("That value is not in the database");
                        }
                        // Add space
                        Console.WriteLine();
                        // Prompt user again
                        isInteger = int.TryParse(Console.ReadLine(), out waterPlantID);
                        isInDB    = db.Plants.Any(p => p.Id == waterPlantID);
                    }
                    // Set the first instance of the ID's matching to waterplant variable
                    var waterPlant = db.Plants.First(p => p.Id == waterPlantID);
                    // UPDATE the lastWateredDate property for that plant to the current time
                    waterPlant.LastWateredDate = DateTime.Today;
                    db.SaveChanges();
                    break;

                // * * * * * VIEW PLANTS NOT WATERED TODAY * * * * *
                case "n":
                    // Add space
                    Console.WriteLine();
                    // Filter plants that haven't been watered today
                    var plantsNotWateredToday = db.Plants.Where(p => p.LastWateredDate != DateTime.Today);
                    foreach (var p in plantsNotWateredToday)
                    {
                        Console.WriteLine("-----------------------------------------------------------------");
                        Console.WriteLine($"Species: {p.Species}");
                        Console.WriteLine($"Last time watered: {p.LastWateredDate.ToString("MMMM dd, yyyy")}");
                        Console.WriteLine("-----------------------------------------------------------------");
                    }
                    db.SaveChanges();
                    // Add space
                    Console.WriteLine();
                    break;

                case "x":
                    // Check to see if plants need to be watered


                    break;

                // * * * * * VIEW plants given a location * * * * *
                case "l":
                    // Add space
                    Console.WriteLine();
                    System.Console.WriteLine("Please choose a location to view all the plants in that location:");
                    var chosenLocation = Console.ReadLine().ToLower();
                    // Add space
                    Console.WriteLine();
                    // Validate to see if location exists in database
                    while (!db.Plants.Any(l => l.LocatedPlant == chosenLocation))
                    {
                        Console.WriteLine(errorMessage);
                        chosenLocation = Console.ReadLine().ToLower();
                    }
                    // Filter plants to the specific location
                    var locatedPlants = db.Plants.Where(p => p.LocatedPlant == chosenLocation);
                    // Loop over each of the plants in the plants that are in the specific location and print species and location
                    foreach (var p in locatedPlants)
                    {
                        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                        Console.WriteLine($"{p.Species}'s location is: {p.LocatedPlant}.");
                        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    }
                    // Add space
                    Console.WriteLine();
                    break;

                // * * * * * QUIT * * * * *
                case "q":
                    // Add Space
                    System.Console.WriteLine();
                    Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    System.Console.WriteLine("Thanks for checking out the flower database!");
                    Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    // Set is running to false and exit while loop
                    isRunning = false;
                    break;
                }
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var db = new PlantContext();

            var isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("Commands: add, remove, water, location, view all, needs water, or quit?");
                var input = Console.ReadLine().ToLower();
                if (input == "quit")
                {
                    isRunning = false;
                }
                else if (input == "add")
                {
                    var newplant = new Plant();

                    Console.WriteLine($"What is your plant's species?");
                    newplant.Species = Console.ReadLine();
                    Console.WriteLine($"Where is your plant located?");
                    newplant.LocatedPlant = Console.ReadLine();
                    Console.WriteLine($"How much light does your plant need?");
                    newplant.LightNeeded = Console.ReadLine();
                    db.Plants.Add(newplant);
                    db.SaveChanges();
                }
                else if (input == "view all")
                {
                    var test = db.Plants.OrderBy(plant => plant.LocatedPlant).ToList();
                    foreach (var plant in test)
                    {
                        Console.WriteLine($"{plant.Species} is located in {plant.LocatedPlant}");
                    }
                }
                else if (input == "remove")
                {
                    Console.WriteLine($"Which plant would you like to remove?");
                    var userRemove = int.Parse(Console.ReadLine());

                    var plantToDelete = db.Plants.First(p => p.Id == userRemove);
                    db.Plants.Remove(plantToDelete);
                    db.SaveChanges();
                }
                else if (input == "water")
                {
                    Console.WriteLine("Which plant would you like to water?");
                    var plantToWaterId = int.Parse(Console.ReadLine());
                    var plantToUpdate  = db.Plants.First(p => p.Id == plantToWaterId);
                    plantToUpdate.LastWateredDate = DateTime.Now;
                    db.SaveChanges();
                }
                else if (input == "location")
                {
                    Console.WriteLine("What location is your plant in?");
                    var plantLocation = Console.ReadLine();
                    var plantPlace    = db.Plants.Where(p => p.LocatedPlant == plantLocation).ToList();
                    foreach (var plant in plantPlace)
                    {
                        Console.WriteLine($"{plant.Species} is in {plantLocation}");
                    }
                }
                else if (input == "needs water")
                {
                    var needsWatering = db.Plants.Where(p => p.LastWateredDate < DateTime.Today).ToList();
                    foreach (var plant in needsWatering)
                    {
                        Console.WriteLine($"{plant.Species} needs watering!");
                    }
                }
            }
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var db = new PlantContext();

            Console.WriteLine("Welcome to Garden Tracker!");
            bool isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("What would you like to do: (VIEW), (PLANT), (REMOVE), (WATER), (QUIT)? ");
                var userInput = Console.ReadLine().ToLower();
                if (userInput != "view" && userInput != "plant" && userInput != "remove" && userInput != "water" && userInput != "quit")
                {
                    Console.WriteLine("That is not a valid input, please choose again from: (VIEW), (PLANT), (REMOVE), (WATER), (QUIT)");
                    userInput = Console.ReadLine().ToLower();
                }
                if (userInput == "view")
                {
                    Console.WriteLine("Would you like to view (ALL), by (LOCATION), or not (WATERED) today?");
                    userInput = Console.ReadLine().ToLower();
                    if (userInput != "all" && userInput != "location" && userInput != "watered")
                    {
                        Console.WriteLine("That is not a valid input, please choose again from: (ALL), by (LOCATION), or not (WATERED) today?");
                        userInput = Console.ReadLine().ToLower();
                    }
                    if (userInput == "all")
                    {
                        Console.Clear();

                        var displayAll = db.Plants.OrderBy(plant => plant.LocatedPlanted);
                        foreach (var plant in displayAll)
                        {
                            Console.WriteLine($"{plant.Id}:{plant.Species} is located in the {plant.LocatedPlanted} and was last watered on {plant.LastWateredDate}.");
                        }
                        //for each loop
                    }
                    if (userInput == "location")
                    {
                        Console.Clear();
                        Console.WriteLine("You have plants in the following locations:");
                        var displayLocation = db.Plants.OrderBy(plant => plant.LocatedPlanted).Distinct();
                        foreach (var l in displayLocation)
                        {
                            Console.WriteLine($"{l.LocatedPlanted}");
                        }
                        // ask user which zone they would like to look at?
                        Console.WriteLine("Which location would you like to view?");
                        // var locationToLook = console readline
                        var locationInput = Console.ReadLine().ToLower();
                        // if (locationInput != db.Plants.Where(plant => plant.LocatedPlanted))

                        // {
                        //   Console.WriteLine("That is not a valid option, please select a valid location.");
                        //   locationInput = Console.ReadLine().ToLower();
                        // }
                        // else if (locationInput == db.Plants.Any(plant => plant.LocatedPlanted))
                        // {

                        // plant => plant.LocatedPlanted == locationInput
                        var displayPlantsByLocation = db.Plants.Where(plant => plant.LocatedPlanted == locationInput);

                        // foreach loop printing each plant in that location
                        Console.Clear();
                        foreach (var locatedPlant in displayPlantsByLocation)
                        {
                            Console.WriteLine($"{locatedPlant.Id}:{locatedPlant.Species} was planted on {locatedPlant.PlantedDate} and needs {locatedPlant.LightNeeded} hours of light and {locatedPlant.WaterNeeded} gallons of water a week.");
                            Console.WriteLine($"{locatedPlant.Species} was planted on {locatedPlant.PlantedDate} and was last watered on {locatedPlant.LastWateredDate}");
                        }
                        // }
                    }
                    if (userInput == "watered")
                    {
                        Console.Clear();
                        Console.WriteLine("The following plants have not been watered today:");
                        var displayWatered = db.Plants.Where(plant => plant.LastWateredDate < DateTime.Today);
                        foreach (var p in displayWatered)
                        {
                            Console.WriteLine("The following plants have not been watered today:");
                            Console.WriteLine($"{p.Species} was last watered on {p.LastWateredDate}");
                        }
                    }
                }
                if (userInput == "plant")
                {
                    Console.Clear();
                    var newPlant = new Plant();
                    Console.WriteLine("What would you like to plant?");
                    newPlant.Species = Console.ReadLine().ToLower();
                    Console.WriteLine($"Where did you plant the {newPlant.Species}?");
                    newPlant.LocatedPlanted = Console.ReadLine().ToLower();
                    Console.WriteLine($"How much light in hours does the {newPlant.Species} need?");
                    newPlant.LightNeeded = double.Parse(Console.ReadLine());
                    Console.WriteLine($"How much water in gallons does {newPlant.Species} need a week?");
                    newPlant.WaterNeeded     = double.Parse(Console.ReadLine().ToLower());
                    newPlant.PlantedDate     = DateTime.Now;
                    newPlant.LastWateredDate = DateTime.Now;


                    db.Add(newPlant);
                    db.SaveChanges();
                }
                if (userInput == "remove")
                {
                    var displayRemove = db.Plants.OrderBy(plant => plant.Id);
                    Console.WriteLine("Which plant would you like to remove?");
                    foreach (var plant in displayRemove)
                    {
                        Console.WriteLine($"{plant.Id}: {plant.Species} located in the {plant.LocatedPlanted}");
                    }

                    Console.WriteLine("What plant would you like to remove? Please enter the plant id from the list above!");
                    var userRemove    = int.Parse(Console.ReadLine());
                    var plantToRemove = db.Plants.FirstOrDefault(plant => plant.Id == userRemove);
                    if (plantToRemove == null)
                    {
                        Console.WriteLine("That is not a valid option, please select a valid id number.");
                        userRemove    = int.Parse(Console.ReadLine());
                        plantToRemove = db.Plants.FirstOrDefault(plant => plant.Id == userRemove);
                    }
                    if (plantToRemove != null)
                    {
                        db.Plants.Remove(plantToRemove);
                        db.SaveChanges();
                    }
                }
                if (userInput == "water")
                {
                    var displayAll = db.Plants.OrderBy(plant => plant.LastWateredDate);
                    foreach (var plant in displayAll)
                    {
                        Console.WriteLine($"{plant.Id}: {plant.Species} was last watered on {plant.LastWateredDate}.");
                    }
                    Console.WriteLine("What plant would you like to water? Please enter the plant id from the list above!");
                    var userWater    = int.Parse(Console.ReadLine());
                    var plantToWater = db.Plants.FirstOrDefault(plant => plant.Id == userWater);
                    if (plantToWater == null)
                    {
                        Console.WriteLine("That is not a valid option, please select a valid id number.");
                        userWater = int.Parse(Console.ReadLine());
                    }
                    if (plantToWater != null)
                    {
                        plantToWater.LastWateredDate = DateTime.Now;
                        db.SaveChanges();
                    }
                }
                else if (userInput == "quit")
                {
                    isRunning = false;
                    Console.Clear();
                    Console.WriteLine("Goodbye");
                }
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            Console.WriteLine(@"                                                _..
                                       ;-._   .'   `\
                                     .'    `\/       ;
                                     |       `\.---._|
                                  .--;   . ( .'      '.
                                 / _  \_  './ _.       `-._
                                ( = \  )`""'\;--.         /
                                {= (|  )     /`.         /     .'|
                                ( =_/  )__..-\         .'     / /
                                 \    }/    / ;.____.-;/\   .` /
                                  '--' |  .'   |       \ \  |  ;
                                       \  '    /       |. ;  \/
                                        )    .'`-.    / ; |  /\
                                       /__.-'   , \_.'  | | ;  ;
                                                |\      |`| |  |
                                                 \`\    | | |  |
                                                  \ `\  | | ;  ;
                                                   |  ; | | /  /
                                                   |  | | |/  /
                  Party Thyme                      ;  | | /  /
                                                    \  \;/  /
                                                     \  \  /
                                                      \  Y/
                                                       |  |
                                                       |  |
                                                       |  |
                                                       |  |
                                                       \  |
                                                        \_/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             Welcome to Party Thyme
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

");
            var db        = new PlantContext();
            var userInput = "";
            var isRunning = true;

            while (isRunning)
            {
                System.Console.WriteLine("What would you like to do?");
                System.Console.WriteLine("");
                System.Console.WriteLine("View 'v' || Plant 'p' || Remove 'r' || Water 'w' || Need to be watered 'n' || Location summary 'l'");
                userInput = Console.ReadLine();
                System.Console.WriteLine("");
                switch (userInput)
                {
                case "v":

                    var orderedPlants = db.Plants.OrderBy(p => p.LocatedPlant);
                    foreach (var p in orderedPlants)
                    {
                        System.Console.WriteLine("-------------------------------------------");
                        System.Console.WriteLine($"Id:                    {p.Id}");
                        System.Console.WriteLine($"Species:               {p.Species}");
                        System.Console.WriteLine($"Location Planted:      {p.LocatedPlant}");
                        System.Console.WriteLine($"Date Planted:          {p.PlantedDate}");
                        System.Console.WriteLine($"Date Last Watered:     {p.LastWateredDate.ToString("MM/dd/yyyy")}");
                        System.Console.WriteLine($"Light needed (hrs/d):  {p.LightNeeded}");
                        System.Console.WriteLine($"WaterNeeded (ml/d):    {p.WaterNeeded}");
                        System.Console.WriteLine("-------------------------------------------");
                        System.Console.WriteLine("");
                    }
                    break;

                case "p":
                    // Ask for Species
                    System.Console.WriteLine("What species is it?");
                    var newSpecies = Console.ReadLine().ToLower();

                    // Ask for Where it was planted
                    System.Console.WriteLine("Where did you plant it?");
                    var newLocatedPlanted = Console.ReadLine().ToLower();

                    // Ask for When it was planted
                    System.Console.WriteLine("When did you plant it?");
                    DateTime newPlantedDate;
                    var      isDate = DateTime.TryParse(Console.ReadLine(), out newPlantedDate);
                    while (!isDate)
                    {
                        System.Console.WriteLine("That is not a valid date. Try again.");
                        isDate = DateTime.TryParse(Console.ReadLine(), out newPlantedDate);
                    }

                    // Ask for The last time it was watered
                    System.Console.WriteLine("When was the last time it was watered?");
                    DateTime newLastWateredDate;
                    isDate = DateTime.TryParse(Console.ReadLine(), out newLastWateredDate);
                    while (!isDate)
                    {
                        System.Console.WriteLine("That is not a valid date. Try again.");
                        isDate = DateTime.TryParse(Console.ReadLine(), out newLastWateredDate);
                    }

                    // Ask for How much light it needs
                    System.Console.WriteLine("How much light does it need per day (in hours)?");
                    int newLightNeeded;
                    var isInt = int.TryParse(Console.ReadLine(), out newLightNeeded);
                    while (!isInt)
                    {
                        System.Console.WriteLine("That is not a number. Try again.");
                        isInt = int.TryParse(Console.ReadLine(), out newLightNeeded);
                    }

                    // Ask for how much water it needs
                    System.Console.WriteLine("How much water does it need per day (in ml)?");
                    int newWaterNeeded;
                    isInt = int.TryParse(Console.ReadLine(), out newWaterNeeded);
                    while (!isInt)
                    {
                        System.Console.WriteLine("That is not a number. Try again.");
                        isInt = int.TryParse(Console.ReadLine(), out newWaterNeeded);
                    }

                    var plantToAdd = new Plant()
                    {
                        Species         = newSpecies,
                        LocatedPlant    = newLocatedPlanted,
                        PlantedDate     = newPlantedDate,
                        LastWateredDate = newLastWateredDate,
                        LightNeeded     = newLightNeeded,
                        WaterNeeded     = newWaterNeeded
                    };

                    db.Plants.Add(plantToAdd);
                    db.SaveChanges();
                    break;

                case "r":
                    // Ask for Which plant to remove (by id)
                    System.Console.WriteLine("Which plant would you like to remove (Id)");
                    int plantToRemoveId;
                    isInt = int.TryParse(Console.ReadLine(), out plantToRemoveId);
                    var isInDb = db.Plants.Any(p => p.Id == plantToRemoveId);
                    while (!isInt || !isInDb)
                    {
                        if (!isInt)
                        {
                            System.Console.WriteLine("That is not a number. Try again.");
                        }
                        else if (!isInDb)
                        {
                            System.Console.WriteLine("That Id is not in the database. Try again.");
                        }

                        isInt  = int.TryParse(Console.ReadLine(), out plantToRemoveId);
                        isInDb = db.Plants.Any(p => p.Id == plantToRemoveId);
                    }

                    var plantToRemove = db.Plants.First(p => p.Id == plantToRemoveId);
                    db.Plants.Remove(plantToRemove);
                    db.SaveChanges();
                    break;

                case "w":
                    System.Console.WriteLine("Which plant would you like to water (Id)");
                    int plantToWaterId;
                    isInt  = int.TryParse(Console.ReadLine(), out plantToWaterId);
                    isInDb = db.Plants.Any(p => p.Id == plantToWaterId);
                    while (!isInt || !isInDb)
                    {
                        if (!isInt)
                        {
                            System.Console.WriteLine("That is not a number. Try again.");
                        }
                        else if (!isInDb)
                        {
                            System.Console.WriteLine("That Id is not in the database. Try again.");
                        }

                        isInt  = int.TryParse(Console.ReadLine(), out plantToWaterId);
                        isInDb = db.Plants.Any(p => p.Id == plantToWaterId);
                    }

                    var plantToWater = db.Plants.First(p => p.Id == plantToWaterId);
                    plantToWater.LastWateredDate = DateTime.Now;

                    db.SaveChanges();


                    break;

                case "n":
                    var today     = DateTime.Today.Date;                                   // "02/26/2020 3:45:32 PM"
                    var dryPlants = db.Plants.Where(p => p.LastWateredDate.Date != today); // "02/26/2020 12:00:00 AM"

                    foreach (var p in dryPlants)
                    {
                        Math.Abs(-1);
                        System.Console.WriteLine("-------------------------------------------");
                        System.Console.WriteLine($"Id:                    {p.Id}");
                        System.Console.WriteLine($"Species:               {p.Species}");
                        System.Console.WriteLine($"Location Planted:      {p.LocatedPlant}");
                        System.Console.WriteLine($"Date Planted:          {p.PlantedDate.ToString("MM/dd/yyyy")}");
                        System.Console.WriteLine($"Date Last Watered:     {p.LastWateredDate.ToString("MM/dd/yyyy")}");
                        System.Console.WriteLine($"Light needed (hrs/d):  {p.LightNeeded}");
                        System.Console.WriteLine($"WaterNeeded (ml/d):    {p.WaterNeeded}");
                        System.Console.WriteLine("-------------------------------------------");
                        System.Console.WriteLine("");
                    }
                    break;

                case "l":
                    System.Console.WriteLine("Which location would you like to view?");
                    var location = Console.ReadLine().ToLower();

                    isInDb = db.Plants.Any(p => p.LocatedPlant == location);

                    while (!isInDb)
                    {
                        System.Console.WriteLine("Sorry that location is not in the database. Try again.");
                        location = Console.ReadLine().ToLower();
                        isInDb   = db.Plants.Any(p => p.LocatedPlant == location);
                    }

                    var plantsByLocation = db.Plants.Where(p => p.LocatedPlant == location);

                    foreach (var p in plantsByLocation)
                    {
                        System.Console.WriteLine("-------------------------------------------");
                        System.Console.WriteLine($"Id:                    {p.Id}");
                        System.Console.WriteLine($"Species:               {p.Species}");
                        System.Console.WriteLine($"Location Planted:      {p.LocatedPlant}");
                        System.Console.WriteLine($"Date Planted:          {p.PlantedDate.ToString("MM/dd/yyyy")}");
                        System.Console.WriteLine($"Date Last Watered:     {p.LastWateredDate.ToString("MM/dd/yyyy")}");
                        System.Console.WriteLine($"Light needed (hrs/d):  {p.LightNeeded}");
                        System.Console.WriteLine($"WaterNeeded (ml/d):    {p.WaterNeeded}");
                        System.Console.WriteLine("-------------------------------------------");
                        System.Console.WriteLine("");
                    }
                    break;

                case "q":
                    isRunning = false;
                    break;
                }
            }
        }
Exemple #13
0
        static void Main(string[] args)
        {
            var db        = new PlantContext();
            var newPlant  = new Plant();
            var isRunning = true;

            while (isRunning)
            {
                Console.Clear();
                Console.WriteLine("         It's PARTY THYME!");
                Console.WriteLine("***************************************");
                Console.WriteLine("     What would you like to do?");
                Console.WriteLine("----------------------------------------");
                Console.WriteLine("(VIEW), (PLANT), (REMOVE), or (WATER)?");
                Console.WriteLine("     Or would you like to (QUIT)?");
                Console.WriteLine("***************************************");
                var main = Console.ReadLine().ToUpper();
                if (main != "VIEW" && main != "PLANT" && main != "REMOVE" && main != "WATER")
                {
                }
                if (main == "VIEW")
                {
                    Console.Clear();
                    Console.WriteLine("**************************************************");
                    Console.WriteLine("What would you like to view?");
                    Console.WriteLine("--------------------------------------------------");
                    Console.WriteLine("(ALL) plants, plant (LOCATION), or (NOT) watered?");
                    Console.WriteLine("**************************************************");
                    var view = Console.ReadLine().ToUpper();
                    // view all plants
                    if (view == "ALL")
                    {
                        var allPlants = db.Plants.OrderBy(plant => plant.LocatedPlanted);
                        Console.WriteLine("\n***************************************");
                        foreach (var plant in allPlants)
                        {
                            Console.WriteLine($"({plant.Id}): {plant.Species} is located in {plant.LocatedPlanted}.");
                        }
                        Console.WriteLine("***************************************");
                        Console.WriteLine("\n\nPress Enter to return to the main menu.");
                        view = Console.ReadLine();
                    }
                    // view plants by location summary
                    else if (view == "LOCATION")
                    {
                        Console.WriteLine("\n***************************************");
                        foreach (var plant in db.Plants.Distinct())
                        {
                            Console.WriteLine($"{plant.LocatedPlanted}");
                        }
                        Console.WriteLine("\n***************************************");
                        Console.WriteLine("What location would you like to view?");
                        var userLocation = Console.ReadLine();
                        var summary      = db.Plants.Any(plant => plant.LocatedPlanted == userLocation);
                        while (!summary)
                        {
                            Console.WriteLine("Location is not found. Try again.");
                            userLocation = Console.ReadLine();
                            summary      = db.Plants.Any(plant => plant.LocatedPlanted == userLocation);
                        }
                        Console.WriteLine("\n***************************************");
                        var location = db.Plants.Where(plant => plant.LocatedPlanted == userLocation);
                        foreach (var plant in location)
                        {
                            Console.Write($"{plant.Species} is in {plant.LocatedPlanted}.\n");
                        }
                        Console.WriteLine("***************************************");
                        Console.WriteLine("\nPress Enter to return to the main menu");
                        view    = Console.ReadLine();
                        summary = false;
                    }
                    // view plants by plants that haven't been watered today
                    else if (view == "NOT")
                    {
                        Console.WriteLine("Here are the plants that have no been watered:");
                        Console.Clear();
                        Console.WriteLine("These are the plants that have not been watered today:");
                        var viewWatered = db.Plants.Where(plant => plant.LastWateredDate < DateTime.Today);
                        foreach (var plant in viewWatered)
                        {
                            Console.WriteLine($"{plant.Species} was watered on {plant.LastWateredDate}.");
                        }
                        Console.WriteLine("Press Enter to return to the main menu");
                        view = Console.ReadLine();
                    }
                }
                // add plants to the database
                else if (main == "PLANT")
                {
                    Console.WriteLine("\n***************************************");
                    Console.WriteLine($"What kind of species is it?");
                    newPlant.Species = Console.ReadLine();
                    Console.WriteLine($"Where was {newPlant.Species} planted?");
                    newPlant.LocatedPlanted = Console.ReadLine();
                    Console.WriteLine($"How many hours of light does the {newPlant.Species} need a day?");
                    newPlant.LightNeeded = double.Parse(Console.ReadLine());
                    Console.WriteLine($"How much water does the {newPlant.Species} need?");
                    newPlant.WaterNeeded     = Console.ReadLine();
                    newPlant.LastWateredDate = DateTime.Now;
                    newPlant.PlantedDate     = DateTime.Now;

                    db.Plants.Add(newPlant);
                    db.SaveChanges();
                }
                // remove plants from database by id
                else if (main == "REMOVE")
                {
                    // displays plants by id, name, and location
                    var allPlants = db.Plants.OrderBy(plant => plant.LocatedPlanted);
                    Console.WriteLine("\n***************************************");
                    foreach (var plant in allPlants)
                    {
                        Console.WriteLine($"{plant.Species} is located in {plant.LocatedPlanted} ({plant.Id}).");
                    }
                    Console.WriteLine("***************************************");
                    Console.WriteLine("Please enter the ID # of the plant you'd like to remove?");
                    var remove        = int.Parse(Console.ReadLine());
                    var plantToRemove = db.Plants.FirstOrDefault(plant => plant.Id == remove);
                    if (plantToRemove != null)
                    {
                        db.Plants.Remove(plantToRemove);
                        db.SaveChanges();
                    }
                }
                // choose what plants need to be watered
                else if (main == "WATER")
                {
                    Console.Clear();
                    var allWatered = db.Plants.OrderBy(plant => plant.LastWateredDate);
                    foreach (var watered in allWatered)
                    {
                        Console.WriteLine($"ID:({watered.Id}) {watered.Species} was last watered on {watered.LastWateredDate}");
                    }
                    Console.WriteLine("Please choose the ID number of the plant you'd like to water.");
                    var userInput    = int.Parse(Console.ReadLine());
                    var plantToWater = db.Plants.FirstOrDefault(plant => plant.Id == userInput);
                    if (plantToWater == null)
                    {
                        Console.WriteLine("That is not a valid ID. Please choose a valid ID number.");
                        userInput = int.Parse(Console.ReadLine());
                    }
                    if (plantToWater != null)
                    {
                        plantToWater.LastWateredDate = DateTime.Now;
                        db.SaveChanges();
                    }
                }
                if (main == "QUIT")
                {
                    isRunning = false;
                }
            }
        }