public void Update(Recipe_IngredientDTO entity)
        {
            Recipe_Ingredient recipe_Ingredient = _mapper.Map <Recipe_Ingredient>(entity);

            _db.GetRecipe_IngredientRepo.Update(recipe_Ingredient);
            _db.Save();
        }
Exemplo n.º 2
0
        public ViewResult AddRecipe(RecipeInput recipeInput)
        {
            Ingredient        temp;
            Recipe            recipe            = new Recipe();
            List <Ingredient> ingredients       = new List <Ingredient>();
            Recipe_Ingredient recipe_ingredient = new Recipe_Ingredient();

            // transfers recipe information from recipeInput to a Recipe object to add in the repository later
            recipe.Title        = recipeInput.Title;
            recipe.TotalTime    = recipeInput.TotalTime;
            recipe.CookTime     = recipeInput.CookTime;
            recipe.Instructions = recipeInput.Instructions;
            recipe.Category     = recipeInput.Category;

            foreach (IngredientInput ingredient in recipeInput.Ingredients) // transfers ingredient names from recipeInput to an Ingredient list to add in the repository later
            {
                temp      = new Ingredient();
                temp.Name = ingredient.Name;
                ingredients.Add(temp);
            }

            recipeRepository.SaveRecipe(recipe);                            // Saves the recipe to the database
            ingredientRepository.SaveIngredients(ingredients);              // Saves the ingredients to the database

            foreach (IngredientInput ingredient in recipeInput.Ingredients) // loads recipe_ingredient information to a recipe_ingredient object to add the database
            {
                try
                {
                    recipe_ingredient.IngredientID = ingredientRepository.Ingredients
                                                     .FirstOrDefault(i => i.Name == ingredient.Name).IngredientID;
                }
                catch (System.NullReferenceException)
                {
                    continue;
                }

                recipe_ingredient.RecipeID = recipeRepository.RecipeList.Last().RecipeID;
                if (ingredient.UnitOfMeasurement == Recipe_Ingredient._unitOfMeasurement.atWill)
                {
                    recipe_ingredient.Quantity = null;
                }
                else
                {
                    recipe_ingredient.Quantity = ingredient.Quantity;
                }
                recipe_ingredient.UnitOfMeasurement = ingredient.UnitOfMeasurement;

                recipe_ingredientRepository.SaveRecipe_Ingredient(recipe_ingredient);
            }

            recipeInput.RecipeID = recipeRepository.RecipeList.FirstOrDefault(r => r.Title == recipeInput.Title).RecipeID;

            return(View("../Recipe/DisplayPage", recipeInput));
        }
Exemplo n.º 3
0
        public ViewResult updateRecipe(RecipeInput recipeInput)
        {
            Ingredient        temp;
            Recipe            recipe            = new Recipe();
            List <Ingredient> ingredients       = new List <Ingredient>();
            Recipe_Ingredient recipe_ingredient = new Recipe_Ingredient();

            // transfers recipe information from recipeInput to a Recipe object to update in the repository later
            recipeInput.RecipeID = Int32.Parse(Request.Form["RecipeID"]);

            recipe.RecipeID     = recipeInput.RecipeID;
            recipe.Title        = recipeInput.Title;
            recipe.TotalTime    = recipeInput.TotalTime;
            recipe.CookTime     = recipeInput.CookTime;
            recipe.Instructions = recipeInput.Instructions;
            recipe.Category     = recipeInput.Category;

            foreach (IngredientInput ingredient in recipeInput.Ingredients) // transfers ingredient names from recipeInput to an Ingredient list to add in the repository later
            {
                temp              = new Ingredient();
                temp.Name         = ingredient.Name;
                temp.IngredientID = ingredient.IngredientID;
                ingredients.Add(temp);
            }

            recipeRepository.SaveRecipe(recipe);               // Saves the recipe to the database
            ingredientRepository.SaveIngredients(ingredients); // Saves the ingredients to the database

            if (!ingredients.Equals(recipeInput.Ingredients))
            {
                foreach (IngredientInput ingredient in recipeInput.Ingredients) // loads recipe_ingredient information to a recipe_ingredient object to add in the database
                {
                    recipe_ingredient = new Recipe_Ingredient();

                    recipe_ingredient.IngredientID      = ingredient.IngredientID;
                    recipe_ingredient.RecipeID          = recipe.RecipeID;
                    recipe_ingredient.Quantity          = ingredient.Quantity;
                    recipe_ingredient.UnitOfMeasurement = ingredient.UnitOfMeasurement;

                    recipe_ingredientRepository.SaveRecipe_Ingredient(recipe_ingredient);
                }
            }

            return(View("../Recipe/DisplayPage", recipeInput));
        }