Example #1
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Recipe> allRecipes = Recipe.GetAll();
         return(View["index.cshtml", allRecipes]);
     };
 }
Example #2
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 #3
0
        public void Test_DatabaseEmptyAtFirst()
        {
            //Arrange, Act
            int result = Recipe.GetAll().Count;

            //Assert
            Assert.Equal(0, result);
        }
        public void Recipe_Save_SavesRecipeToDb()
        {
            Recipe newRecipe = new Recipe("soup", "heat up");

            newRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];

            Assert.Equal(newRecipe, savedRecipe);
        }
Example #5
0
        public void Recipe_DatebaseIsEmpty_True()
        {
            //Arrange
            List <Recipe> expectedList = new List <Recipe> {
            };
            List <Recipe> actualList   = Recipe.GetAll();

            //Assert
            Assert.Equal(expectedList, actualList);
        }
        public void Recipe_DatabaseIsEmpty_True()
        {
            //Arrange:  manual data
            List <Recipe> expectedList = new List <Recipe> {
            };
            //Act : the method we're testing
            List <Recipe> resultList = Recipe.GetAll();

            // Assert
            Assert.Equal(expectedList, resultList);
        }
Example #7
0
        public void Save_SaveToDatabase_SaveWithId()
        {
            Recipe testRecipe = new Recipe("Chicken Soup", "<Chicken> <Chicken Broth", "Boil broth, cook chicken, put chicken in broth", 4, "30 mins");

            testRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];

            int output   = savedRecipe.GetId();
            int expected = testRecipe.GetId();

            Assert.Equal(expected, output);
        }
Example #8
0
        public void Save_RecipeIsSavedToDatabase_True()
        {
            //Arrange
            Recipe newRecipe = new Recipe("Soup", "Heat up Soup");

            //Act
            newRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];

            //Assert
            Assert.Equal(newRecipe, savedRecipe);
        }
Example #9
0
        public void Save_SaveToDatabase_Save()
        {
            Recipe testRecipe = new Recipe("Chicken Soup", "<Chicken, <Chicken Broth", "Boil broth, cook chicken, put chicken in broth", 4, "30 mins");

            testRecipe.Save();

            List <Recipe> result = Recipe.GetAll();
            List <Recipe> verify = new List <Recipe> {
                testRecipe
            };

            Assert.Equal(verify, result);
        }
Example #10
0
        public void Test_Save_AssignsIdToObject()
        {
            string url        = "www.epicodus.com";
            Recipe testRecipe = new Recipe("Spaghetti", "Noodles, Sauce", "Boil noodles", "20 Minutes", 5, url);

            testRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];

            int result = savedRecipe.GetId();
            int testId = testRecipe.GetId();

            Assert.Equal(testId, result);
        }
        public HomeModule()
        {
            // root -> list all recipes
            Get["/"] = _ => {
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };

            // recipes add
            Get["/recipes/add"] = _ => {
                Post[""]
            };
        }
    }
Example #12
0
        public void Save_SavesRecipeToDB_true()
        {
            //Arrange
            Recipe newRecipe      = new Recipe("Chicken Soup", "Lina", "Soup");
            Recipe expectedRecipe = new Recipe("Chicken Soup", "Lina", "Soup");

            //Act
            newRecipe.Save();
            List <Recipe> allRecipe = Recipe.GetAll();

            newRecipe = allRecipe[0];
            //Assert
            Assert.Equal(expectedRecipe, newRecipe);
        }
Example #13
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Mac and cheese", "cheese and noodles", "cook it", 5);

            //Act
            testRecipe.Save();
            List <Recipe> result   = Recipe.GetAll();
            List <Recipe> testList = new List <Recipe> {
                testRecipe
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #14
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Spicy Yaki Soba", "Spicy, Soba", "Pour Spicy into Soba");

            //Act
            testRecipe.Save();
            List <Recipe> result   = Recipe.GetAll();
            List <Recipe> testList = new List <Recipe> {
                testRecipe
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #15
0
        public void SortByRate_ListOfRecipes_SortedDesc()
        {
            Recipe recipe1 = new Recipe("Spaghetti", "<Pasta, <Marinara Sauce", "Boil water, cook pasta, strain pasta, add sauce", 5, "30 mins");
            Recipe recipe2 = new Recipe("Spaghetti", "<Pasta, <Marinara Sauce", "Boil water, cook pasta, strain pasta, add sauce", 4, "30 mins");

            recipe1.Save();
            recipe2.Save();

            List <Recipe> result   = Recipe.GetAll();
            List <Recipe> expected = new List <Recipe> {
                recipe1, recipe2
            };

            Assert.Equal(expected, result);
        }
Example #16
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Mac and cheese", "cheese and noodles", "cook it", 5);

            //Act
            testRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];


            int result = savedRecipe.GetId();
            int testId = testRecipe.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Example #17
0
        public void Test_DeleteRecipe_DeleteRecipeFromDatabase()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Spaghetti", "<Pasta, <Marinara Sauce", "Boil water, cook pasta, strain pasta, add sauce", 5, "30 mins");

            //Act
            testRecipe.Save();
            testRecipe.Delete();

            //Assert
            List <Recipe> expectedResult = new List <Recipe> {
            };
            List <Recipe> actualResult   = Recipe.GetAll();

            Assert.Equal(expectedResult, actualResult);
        }
Example #18
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Spicy Yaki Soba", "Spicy, Soba", "Pour Spicy into Soba");

            //Act
            testRecipe.Save();
            Recipe savedRecipe = Recipe.GetAll()[0];


            int result = savedRecipe.GetId();
            int testId = testRecipe.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Example #19
0
        public void Test_Delete_DeleteSingleRecipe()
        {
            //Arrange
            string url         = "www.epicodus.com";
            Recipe testRecipe1 = new Recipe("Spaghetti", "Noodles, Sauce", "Boil noodles", "20 Minutes", 5, url);

            testRecipe1.Save();

            Recipe testRecipe2 = new Recipe("Spaghetti", "Noodles, Sauce", "Boil noodles", "20 Minutes", 5, url);

            testRecipe2.Save();

            //Act
            testRecipe1.DeleteRecipe();
            List <Recipe> result     = Recipe.GetAll();
            List <Recipe> resultList = new List <Recipe> {
                testRecipe2
            };

            Assert.Equal(result, resultList);
        }
Example #20
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]);
            };
        }
Example #21
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };
            Get["/new-recipe"] = _ => {
                return(View["recipe_form.cshtml"]);
            };

            Post["/recipe/added"] = _ => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], "", "", 0, "");
                newRecipe.Save();
                List <String> IngredientNames = new List <String> {
                };
                string Ingredients            = newRecipe.GetIngredients();
                if (Ingredients != "")
                {
                    string[] IngredientsArray = Ingredients.Split(' ');
                    foreach (string name in IngredientsArray)
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 1));
                    }
                }
                else
                {
                    IngredientNames = new List <String> {
                        "You have no ingredients so far"
                    };
                }
                List <String> Instructions = new List <String> {
                };
                string InstructionsString  = newRecipe.GetInstructions();
                if (InstructionsString != "")
                {
                    string[] InstructionsArray = InstructionsString.Split(' ');
                    foreach (string name in  InstructionsArray)
                    {
                        Console.WriteLine(name);
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                else
                {
                    Instructions = new List <String> {
                        "You have no steps of instructions so far"
                    };
                }
                Dictionary <string, object> model = new Dictionary <string, object> {
                    { "recipe", newRecipe }, { "ingredients", IngredientNames }, { "instructions", Instructions }
                };
                return(View["recipe.cshtml", model]);
            };

            Post["/{id}/ingredient/added"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                Console.WriteLine("ingredient-name");
                thisRecipe.AddIngredient(Request.Form["ingredient-name"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> model = new Dictionary <string, object> {
                    { "recipe", thisRecipe }, { "ingredients", IngredientNames }, { "instruction", Instructions }
                };
                return(View["recipe.cshtml", model]);
            };

            Post["/{id}/instructions/added"] = parameters =>
            {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                thisRecipe.AddInstruction(Request.Form["instructions"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> model = new Dictionary <string, object> {
                    { "recipe", thisRecipe }, { "ingredients", IngredientNames }, { "instruction", Instructions }
                };
                return(View["recipe.cshtml", model]);
            };
            Post["/recipe/{id}"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                thisRecipe.Update(null, null, null, int.Parse(Request.Form["star"]), Request.Form["time"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe-info.cshtml", Model]);
            };
            Delete["/deleteall"] = _ => {
                Recipe.DeleteAll();
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };
            Get["/recipe/{id}/info"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe-info.cshtml", Model]);
            };

            Delete["/recipe/{id}/delete"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                thisRecipe.Delete();
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };

            Get["/recipe/{id}/update"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
            Patch["/{id}/update/ingredient/{IngredientName}"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if (!((String.IsNullOrEmpty(name)) || (name.Substring(1, name.Length - 2) == (string)parameters.IngredientName)))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                thisRecipe.AddIngredients(IngredientNames);
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
            Post["/{id}/ingredient/update/added"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                Console.WriteLine("ingredient-name");
                thisRecipe.AddIngredient(Request.Form["ingredient-name"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
            Patch["/{id}/update/instructions/{InstructionName}"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if (!(String.IsNullOrEmpty(name)))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                thisRecipe.AddIngredients(IngredientNames);
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if (!((String.IsNullOrEmpty(name)) || (name.Substring(1, name.Length - 2) == (string)parameters.InstructionName)))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                thisRecipe.AddInstructions(Instructions);
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
        }
Example #22
0
        public void Test_DatabaseIsEmptyAtFirst()
        {
            int result = Recipe.GetAll().Count;

            Assert.Equal(0, result);
        }
Example #23
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };

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

            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["categories.cshtml", Category.GetAll()]);
            };

            Get["/recipes/new"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["recipes_form.cshtml", AllCategories]);
            };
            Post["/recipes/new"] = _ => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], Request.Form["recipe-ingredient"], Request.Form["recipe-instruction"], Request.Form["recipe-rating"]);
                newRecipe.Save();
                return(View["recipes.cshtml", Recipe.GetAll()]);
            };

            Get["recipes/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe          SelectedRecipe    = Recipe.Find(parameters.id);
                List <Category> RecipeCategories  = SelectedRecipe.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("recipe", SelectedRecipe);
                model.Add("recipeCategories", RecipeCategories);
                model.Add("allCategories", AllCategories);
                return(View["recipe.cshtml", model]);
            };
            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var           SelectedCategory    = Category.Find(parameters.id);
                var           CategoryRecipes     = SelectedCategory.GetRecipes();
                List <Recipe> AllRecipes          = Recipe.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryRecipes", CategoryRecipes);
                model.Add("allRecipes", AllRecipes);
                return(View["category.cshtml", model]);
            };

            Post["/recipe/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Recipe   recipe   = Recipe.Find(Request.Form["recipe-id"]);
                recipe.AddCategory(category);
                return(View["category-list.cshtml", recipe.GetCategories()]);
            };
            Post["/category/add_recipe"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Recipe   recipe   = Recipe.Find(Request.Form["recipe-id"]);
                category.AddRecipe(recipe);
                return(View["recipe-list.cshtml", category.GetRecipes()]);
            };

            Patch["/category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.UpdateCategories(Request.Form["new-category-name"]);
                return(View["categories.cshtml", Category.GetAll()]);
            };
            Patch["/recipe/edit/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                SelectedRecipe.UpdateRecipes(Request.Form["new-recipe-name"], Request.Form["new-recipe-ingredient"], Request.Form["new-recipe-instruction"], Request.Form["new-recipe-rating"]);
                return(View["recipes.cshtml", Recipe.GetAll()]);
            };

            Get["/recipes/detail/{id}"] = parameters =>
            {
                Recipe recipe = Recipe.Find(parameters.id);
                return(View["recipe-detail.cshtml", recipe]);
            };

            Delete["/categories/{id}"] = parameters =>
            {
                Category targetCategory = Category.Find(parameters.id);
                targetCategory.Delete();
                return(View["categories.cshtml", Category.GetAll()]);
            };
            Delete["/recipes/{id}"] = parameters =>
            {
                Recipe targetRecipe = Recipe.Find(parameters.id);
                targetRecipe.Delete();
                return(View["recipes.cshtml", Recipe.GetAll()]);
            };

            Post["/recipe/search/results"] = _ => {
                List <Recipe> FoundList = new List <Recipe> {
                };
                Recipe foundRecipe      = Recipe.FindByIngredient(Request.Form["recipe-search"]);
                FoundList.Add(foundRecipe);
                return(View["search.cshtml", FoundList]);
            };

            Post["/categories/delete"] = _ => {
                Category.DeleteAll();
                Recipe.DeleteAll();
                return(View["index.cshtml"]);
            };
            Post["/recipes/delete"] = _ => {
                Recipe.DeleteAll();
                return(View["index.cshtml"]);
            };
        }
Example #24
0
        public void GetAll_DatabaseEmptyAtFirst_Empty()
        {
            int result = Recipe.GetAll().Count;

            Assert.Equal(0, result);
        }
Example #25
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };

            Get["/recipe/new"] = _ => {
                return(View["category_recipes.cshtml"]);
            };

            Post["/"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["index.cshtml", Category.GetAll()]);
            };

            Post["/category/{id}/recipe/new"] = parameters => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], Request.Form["recipe-ingredients"], Request.Form["recipe-instructions"]);
                newRecipe.Save();
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.AddRecipe(newRecipe);
                Dictionary <string, object> model = new Dictionary <string, object>();
                List <Recipe> RecipeList          = SelectedCategory.GetRecipes();
                model.Add("category", SelectedCategory);
                model.Add("recipes", RecipeList);

                return(View["category_recipes.cshtml", model]);
            };

            Get["/category/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category      SelectedCategory    = Category.Find(parameters.id);
                List <Recipe> RecipeList          = SelectedCategory.GetRecipes();
                model.Add("category", SelectedCategory);
                model.Add("recipes", RecipeList);
                return(View["category_recipes.cshtml", model]);
            };

            Get["/recipe/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe          SelectedRecipe    = Recipe.Find(parameters.id);
                List <Category> RecipeCategory    = SelectedRecipe.GetCategories();
                model.Add("recipe", SelectedRecipe);
                return(View["index.cshtml"]);
            };

            Delete["/category/delete/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category SelectedCategory         = Category.Find(parameters.id);
                SelectedCategory.Delete();
                model.Add("category", SelectedCategory);
                return(View["success.cshtml", model]);
            };

            Get["/recipe/delete/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                return(View["category_recipes.cshtml", SelectedRecipe]);
            };

            Patch["/recipe/edit/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                SelectedRecipe.UpdateRecipe(Request.Form["recipe-name"], Request.Form["recipe-ingredients"], Request.Form["recipe-instructions"]);
                return(View["success.cshtml", Recipe.GetAll()]);
            };


            Delete["/recipe/delete/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe SelectedRecipe             = Recipe.Find(parameters.id);
                SelectedRecipe.Delete();
                model.Add("recipe", SelectedRecipe);
                return(View["success.cshtml", model]);
            };
        }