Example #1
0
        public void Test_Update_UpdateRecipe()
        {
            string url         = "www.epicodus.com";
            string name        = "Spaghetti";
            Recipe testRecipe1 = new Recipe(name, "Noodles, Sauce", "Boil noodles", "20 Minutes", 5, url);

            testRecipe1.Save();

            string newName         = "Chicken Tandoori";
            string newIngredients  = "Chicken,Onions,Tomato";
            string newInstructions = "Roast Chicken";
            string newCookTime     = "30 minutes";
            int    newRating       = 5;
            string newUrl          = "www.google.com";

            testRecipe1.Update(newName, newIngredients, newInstructions, newCookTime, newRating, newUrl);
            Recipe actualResult = Recipe.GetAll()[0];

            Assert.Equal(newName, actualResult.GetName());
            Assert.Equal(newIngredients, actualResult.GetIngredients());
            Assert.Equal(newInstructions, actualResult.GetInstructions());
            Assert.Equal(newCookTime, actualResult.GetTime());
            Assert.Equal(newRating, actualResult.GetRating());
            Assert.Equal(newUrl, actualResult.GetUrl());
        }
Example #2
0
 public override bool Equals(System.Object otherRecipe)
 {
     if (!(otherRecipe is Recipe))
     {
         return(false);
     }
     else
     {
         Recipe newRecipe           = (Recipe)otherRecipe;
         bool   idEquality          = (this.GetId() == newRecipe.GetId());
         bool   nameEquality        = (this.GetName() == newRecipe.GetName());
         bool   ingredientEquality  = (this.GetIngredients() == newRecipe.GetIngredients());
         bool   instructionEquality = (this.GetInstructions() == newRecipe.GetInstructions());
         bool   cookTimeEquality    = (this.GetTime() == newRecipe.GetTime());
         bool   ratingEquality      = (this.GetRating() == newRecipe.GetRating());
         bool   urlEquality         = (this.GetUrl() == newRecipe.GetUrl());
         return(idEquality && nameEquality && ingredientEquality && instructionEquality && cookTimeEquality && ratingEquality && urlEquality);
     }
 }
Example #3
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View ["index.cshtml"]);
            };

            //For Recipes..............>

            Get["/recipes"] = _ => {
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["recipes.cshtml", AllRecipes]);
            };

            Get["/recipe/new"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["recipe_form.cshtml", AllCategories]);
            };

            Post["/recipes"] = _ => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], Request.Form["ingredients"], Request.Form["instructions"], Request.Form["cook-time"], Request.Form["rating"], Request.Form["recipe-url"]);
                newRecipe.Save();
                Console.WriteLine("The URL is: " + newRecipe.GetUrl());
                newRecipe.AddCategory(Category.Find(Request.Form["category-id"]));
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["recipes.cshtml", AllRecipes]);
            };

            Get["/recipe/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedRecipe = Recipe.Find(parameters.id);
                var CategoryRecipe = SelectedRecipe.GetCategories();
                model.Add("recipe", SelectedRecipe);
                model.Add("categories", CategoryRecipe);
                return(View["recipe_details.cshtml", model]);
            };

            Get["/recipe/edit/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                return(View["recipe_edit.cshtml", SelectedRecipe]);
            };
            Patch["/recipe/edit/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                SelectedRecipe.Update(Request.Form["recipe-name"], Request.Form["ingredients"], Request.Form["instructions"], Request.Form["cook-time"], Request.Form["rating"], Request.Form["recipe-url"]);
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["recipes.cshtml", AllRecipes]);
            };

            Post["/recipes/delete"] = _ => {
                Recipe.DeleteAll();
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["recipes.cshtml", AllRecipes]);
            };

            Get["recipe/delete/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                return(View["recipe_delete.cshtml", SelectedRecipe]);
            };
            Delete["recipe/delete/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                SelectedRecipe.DeleteRecipe();
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["recipes.cshtml", AllRecipes]);
            };

            //For Categories......................>

            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Get["/category/new"] = _ => {
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["category_form.cshtml", AllRecipes]);
            };

            Post["/categories"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                newCategory.AddRecipe(Recipe.Find(Request.Form["recipe-id"]));
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Get["/category/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedCategory = Category.Find(parameters.id);
                var CategoryRecipe   = SelectedCategory.GetRecipe();
                model.Add("category", SelectedCategory);
                model.Add("recipe", CategoryRecipe);
                return(View["categories_details.cshtml", model]);
            };


            Get["/category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                return(View["category_edit.cshtml", SelectedCategory]);
            };
            Patch["/category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.Update(Request.Form["category-name"]);
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Post["/categories/delete"] = _ => {
                Category.DeleteAll();
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Get["category/delete/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                return(View["category_delete.cshtml", SelectedCategory]);
            };
            Delete["category/delete/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.DeleteCategory();
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };
        }