示例#1
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;
                }
            }
        }
示例#2
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");
                }
            }
        }
示例#3
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;
                }
            }
        }