Example #1
0
        public AddRecipe DeleteRecipe(int recipeId)
        {
            AddRecipe recipeEntry = context.AddRecipes
                                    .FirstOrDefault(r => r.RecipeID == recipeId);

            if (recipeEntry != null)
            {
                context.AddRecipes.Remove(recipeEntry);
                context.SaveChanges();
            }

            return(recipeEntry);
        }
Example #2
0
        public void SaveRecipe(AddRecipe addRecipe, Cuisine cuisine)
        {
            List <Cuisine> cuisineList = new List <Cuisine>();

            cuisineList = context.Cuisines.ToList();

            foreach (var item in cuisineList)
            {
                if (cuisine.CuisineType.Equals(item.CuisineType))
                {
                    addRecipe.Cuisine = cuisineList.Find(c => c.CuisineType == item.CuisineType);
                }
            }

            if (addRecipe.RecipeID == 0)
            {
                context.AddRecipes.Add(addRecipe);
            }
            else
            {
                AddRecipe recipeEntry = context.AddRecipes
                                        .FirstOrDefault(r => r.RecipeID == addRecipe.RecipeID);

                Cuisine cuisineEntry = context.Cuisines
                                       .FirstOrDefault(c => c.CuisineID == cuisine.CuisineID);

                if (recipeEntry != null)
                {
                    recipeEntry.Name             = addRecipe.Name;
                    recipeEntry.Cuisine          = addRecipe.Cuisine;
                    recipeEntry.DifficultyLevel  = addRecipe.DifficultyLevel;
                    recipeEntry.CookingTimeInMin = addRecipe.CookingTimeInMin;
                    recipeEntry.IngredientList   = addRecipe.IngredientList;
                    recipeEntry.Description      = addRecipe.Description;
                }
                if (cuisineEntry != null)
                {
                    cuisineEntry.CuisineType = cuisine.CuisineType;
                }
            }
            context.SaveChanges();
        }
Example #3
0
 public void AddRecipes(AddRecipe addRecipe)
 {
     recipes.Add(addRecipe);
 }