public ActionResult DeleteConfirmed(int id)
        {
            IngredientRecipe ingredientRecipe = db.IngredientRecipe.Find(id);

            db.IngredientRecipe.Remove(ingredientRecipe);
            db.SaveChanges();
            return(RedirectToAction("Index", "Recipies"));
        }
 public ActionResult Edit([Bind(Include = "ID,IdRecipes,IdIngredients,AbsolutQuantity,AbsolutUnitMeasure")] IngredientRecipe ingredientRecipe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ingredientRecipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Recipies"));
     }
     ViewBag.IdIngredients = new SelectList(db.Ingredients, "ID", "Description", ingredientRecipe.IdIngredients);
     ViewBag.IdRecipes     = new SelectList(db.Recipies, "ID", "Description", ingredientRecipe.IdRecipes);
     return(View(ingredientRecipe));
 }
        public ActionResult AddOrUpdate(IngredientRecipeFormViewModel ingredient)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.MessageError = "Il y a des erreurs dans le formulaire";
                return View("Form", ingredient);
            }

            if (ingredient == null)
            {
                return HttpNotFound();
            }

            if (ingredient.IngredientsRecipe.Id > 0)
            {
                IngredientRecipe ingredientFromDb = _ctx.IngredientRecipe.Include(m => m.IngredientIndex).FirstOrDefault(m => m.Id == ingredient.IngredientsRecipe.Id);

                if (ingredientFromDb == null)
                    return HttpNotFound();

                ingredientFromDb.IngredientIndexId = ingredient.IngredientsRecipe.IngredientIndexId;
                ingredientFromDb.Quantity = ingredient.IngredientsRecipe.Quantity;
                ingredientFromDb.Size = ingredient.IngredientsRecipe.Size;
                ingredientFromDb.WeightCl = ingredient.IngredientsRecipe.WeightCl;
                ingredientFromDb.WeightGrams = ingredient.IngredientsRecipe.WeightGrams;

                _ctx.SaveChanges();

                TempData["MessageSuccess"] = "L'ingrédient a bien été modifiée.";
            }
            else
            {
                IngredientRecipe newIngredient = new IngredientRecipe()
                {
                    RecipeId = ingredient.IngredientsRecipe.RecipeId,
                    IngredientIndexId = ingredient.IngredientsRecipe.IngredientIndexId,
                    Quantity = ingredient.IngredientsRecipe.Quantity,
                    Size = ingredient.IngredientsRecipe.Size,
                    WeightCl = ingredient.IngredientsRecipe.WeightCl,
                    WeightGrams = ingredient.IngredientsRecipe.WeightGrams                    
                };
                
                _ctx.IngredientRecipe.Add(newIngredient);
                _ctx.SaveChanges();

                TempData["MessageSuccess"] = "L'ingrédient a bien été ajouté.";
            }
            

            return RedirectToAction("Detail", "Recipe", new { id = ingredient.IngredientsRecipe.RecipeId });
        }
        public ActionResult Delete(int id)
        {
            IngredientRecipe ingRecipe = _ctx.IngredientRecipe.FirstOrDefault(m => m.Id == id);

            if (ingRecipe == null)
                return HttpNotFound();

            _ctx.IngredientRecipe.Remove(ingRecipe);
            _ctx.SaveChanges();

            TempData["MessageSuccess"] = "L'ingrédient a bien été supprimé.";

            return RedirectToAction("Detail", "Recipe", new { id = ingRecipe.RecipeId });
        }
        // GET: IngredientRecipes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IngredientRecipe ingredientRecipe = db.IngredientRecipe.Find(id);

            if (ingredientRecipe == null)
            {
                return(HttpNotFound());
            }
            return(View(ingredientRecipe));
        }
        protected void ButtonAddIngredientToRecipe_Click(object sender, EventArgs e)
        {
            BulletedListIngredients.Items.Add(new ListItem(TextBoxIngredientQuantity.Text + " " + DropDownListMeasurementUnit.SelectedItem.Text + " of " + DropDownListIngredient.SelectedItem.Text));

            Ingredient       newIngredient       = new Ingredient(int.Parse(DropDownListIngredient.SelectedValue), DropDownListIngredient.SelectedItem.Text);
            MeasurementUnit  newMeasurementUnit  = new MeasurementUnit(int.Parse(DropDownListMeasurementUnit.SelectedValue), DropDownListMeasurementUnit.SelectedItem.Text);
            IngredientRecipe newingredientRecipe = new IngredientRecipe(decimal.Parse(TextBoxIngredientQuantity.Text), newIngredient, newMeasurementUnit);

            DAL.Recipe recipe = (DAL.Recipe)Session["newRecipe"];

            recipe.AddIngredientRecipe(newingredientRecipe);

            Session["newRecipe"] = recipe;
        }
        // GET: IngredientRecipes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IngredientRecipe ingredientRecipe = db.IngredientRecipe.Find(id);

            if (ingredientRecipe == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdIngredients = new SelectList(db.Ingredients, "ID", "Description", ingredientRecipe.IdIngredients);
            ViewBag.IdRecipes     = new SelectList(db.Recipies, "ID", "Description", ingredientRecipe.IdRecipes);
            return(View(ingredientRecipe));
        }
        public ActionResult Edit(int id)
        {
            if (id == 0)
                return HttpNotFound();

            IngredientRecipe ingRecipeInDb = _ctx.IngredientRecipe.Include(m => m.IngredientIndex)
                                                                  .FirstOrDefault(m => m.Id == id);
            IngredientRecipeFormViewModel ingRecipeFVM = new IngredientRecipeFormViewModel()
            {
                IngredientsRecipe = ingRecipeInDb,
                IngredientsIndexForDropDown = _ctx.IngredientIndex.ToList()
            };

            return View("Form", ingRecipeFVM);

            
        }
Exemple #9
0
        public async Task linkIngredientAsync(string name, int ingredientId)
        {
            Recipe temp1 = await ctx.recipes.FirstAsync(r => r.recipeName.Equals(name));

            Ingredient temp2 = await ctx.ingredients.FirstAsync(i => i.ingredientId == ingredientId);

            IngredientRecipe ir3 = new IngredientRecipe()
            {
                ingredient = temp2,
                recipe     = temp1
            };

            if (temp1.IngredientRecipes == null)
            {
                temp1.IngredientRecipes = new List <IngredientRecipe>();
            }
            temp1.IngredientRecipes.Add(ir3);
            await ctx.SaveChangesAsync();
        }
Exemple #10
0
        public DieterMutation(ResourcesDbContext db,
                              UserManager <AppUser> userManager,
                              SignInManager <AppUser> signInManager)
        {
            Field <UserType>(
                "registerUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <RegisterUserInputType> > {
                Name = "user"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var user     = context.GetArgument <User>("user");
                var password = context.GetArgument <string>("password");

                var result = userManager.CreateAsync(
                    new AppUser()
                {
                    UserName = user.UserName,
                    Email    = user.Email
                }, password).Result;

                if (!result.Succeeded)
                {
                    return(null);
                }
                user.RegistrationDate = DateTime.Now;
                user.LastActive       = DateTime.Now;
                db.Users.Add(user);
                db.SaveChanges();
                return(user);
            });


            Field <RecipeType>(
                "addRecipe",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AddRecipeInputType> >
            {
                Name = "recipe"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > >
            {
                Name = "ingredientIds"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "authorUserId"
            }),
                resolve: context =>
            {
                var recipe       = context.GetArgument <Recipe>("recipe");
                var ingredients  = context.GetArgument <List <int> >("ingredientIds");
                var authorUserId = context.GetArgument <int>("authorUserId");

                //add rating record
                var rating = new Rating();
                db.Ratings.Add(rating);
                db.SaveChanges();
                recipe.Rating = rating;

                //add user
                var user      = db.Users.FirstOrDefault(x => x.UserId == authorUserId);
                recipe.Author = user;

                //add recipe
                db.Recipes.Add(recipe);
                db.SaveChanges();

                //add ingredients
                foreach (var ingredientId in ingredients)
                {
                    var ingredientRecipe          = new IngredientRecipe();
                    ingredientRecipe.RecipeId     = recipe.RecipeId;
                    ingredientRecipe.IngredientId = ingredientId;
                    db.IngredientRecipes.Add(ingredientRecipe);
                }

                db.SaveChanges();


                return(recipe);
            });

            Field <IngredientType>(
                "addIngredient",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AddIngredientInputType> >
            {
                Name = "ingredient"
            }),
                resolve: context =>
            {
                var ingredient = context.GetArgument <Ingredient>("ingredient");

                db.Ingredients.Add(ingredient);
                db.SaveChanges();

                return(ingredient);
            });

            Field <CommentType>(
                "addComment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AddCommentInputType> > {
                Name = "comment"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "authorUserId"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "recipeId"
            }),
                resolve: context =>
            {
                var comment      = context.GetArgument <Comment>("comment");
                var authorUserId = context.GetArgument <int>("authorUserId");
                var recipeId     = context.GetArgument <int>("recipeId");

                //add rating record
                var rating = new Rating();
                db.Ratings.Add(rating);
                db.SaveChanges();
                comment.Rating = rating;

                //add author
                comment.Author = db.Users.FirstOrDefault(x => x.UserId == authorUserId);
                //add recipe
                comment.Recipe = db.Recipes.FirstOrDefault(x => x.RecipeId == recipeId);

                //add comment
                comment.PublicationDate = DateTime.Now;
                db.Comments.Add(comment);
                db.SaveChanges();

                return(comment);
            });
            Field <UserType>(
                "loginUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "userName"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var userName = context.GetArgument <string>("userName");
                var password = context.GetArgument <string>("password");

                var identityUser = userManager.FindByNameAsync(userName).Result;
                if (identityUser == null)
                {
                    return(null);
                }

                var result = signInManager
                             .CheckPasswordSignInAsync(identityUser, password, false).Result;

                if (!result.Succeeded)
                {
                    return(null);
                }
                var user = db.Users.FirstOrDefault(x => x.UserName == userName);
                if (user == null)
                {
                    return(null);
                }
                user.LastActive = DateTime.Now;
                db.SaveChanges();
                return(user);
            });

            /*Field<PhotoType>(
             *  "addPhoto",
             *  arguments: new QueryArguments(
             *      new QueryArgument<NonNullGraphType<AddPhotoInputType>> {Name = "photo"},
             *      new QueryArgument<IdGraphType> {Name = "recipeId"},
             *      new QueryArgument<IdGraphType> {Name = "ingredientId"}),
             *  resolve: context =>
             *  {
             *      var photo = context.GetArgument<Photo>("photo");
             *      var recipeId = context.GetArgument<int?>("recipeId");
             *      var ingredientId = context.GetArgument<int?>("ingredientId");
             *      if ((ingredientId == null && recipeId == null) || (ingredientId != null && recipeId != null))
             *      {
             *          return null;
             *      }
             *      else
             *      {
             *          db.Photos.Add(photo);
             *          db.SaveChanges();
             *          if (recipeId != null)
             *          {
             *              var recipe = db.Recipes.FirstOrDefault(x => x.RecipeId == recipeId);
             *              if (recipe != null) recipe.Photo = photo;
             *          }
             *          else
             *          {
             *              var ingredient = db.Ingredients.FirstOrDefault(x => x.IngredientId == ingredientId);
             *              if (ingredient != null) ingredient.Photo = photo;
             *          }
             *
             *          db.SaveChanges();
             *
             *          return photo;
             *      }
             *  });*/
            Field <IngredientRecipeType>(
                "assignIngredient",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "ingredientId"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "recipeId"
            }),
                resolve: context =>
            {
                var recipeId     = context.GetArgument <int>("recipeId");
                var ingredientId = context.GetArgument <int>("ingredientId");

                var ingredientRecipe          = new IngredientRecipe();
                ingredientRecipe.RecipeId     = recipeId;
                ingredientRecipe.IngredientId = ingredientId;
                db.IngredientRecipes.Add(ingredientRecipe);
                db.SaveChanges();

                return(ingredientRecipe);
            }
                );
            Field <UserType>(
                name: "vote",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "userId"
            },
                    new QueryArgument <IdGraphType> {
                Name = "recipeId"
            },
                    new QueryArgument <IdGraphType> {
                Name = "commentId"
            },
                    new QueryArgument <NonNullGraphType <VoteTypeEnum> > {
                Name = "voteType"
            }),
                resolve: context =>
            {
                var userId    = context.GetArgument <int>("userId");
                var recipeId  = context.GetArgument <int?>("recipeId");
                var commentId = context.GetArgument <int?>("commentId");
                var voteType  = context.GetArgument <VoteType>("voteType");
                var user      = db.Users
                                .FirstOrDefault(x => x.UserId == userId);

                if (recipeId == null && commentId == null)
                {
                    return(null);
                }

                Rating rating = null;
                if (recipeId != null)
                {
                    rating = db.Recipes
                             .Where(x => x.RecipeId == recipeId)
                             .Select(x => x.Rating)
                             .FirstOrDefault();
                }
                else
                {
                    rating = db.Comments
                             .Where(x => x.CommentId == commentId)
                             .Select(x => x.Rating)
                             .FirstOrDefault();
                }


                var checkUserVoted = db.UserVotes
                                     .Where(x => x.Rating == rating)
                                     .FirstOrDefault(x => x.User == user);

                if (checkUserVoted != null)
                {
                    return(null);
                }

                switch (voteType)
                {
                case VoteType.Up:
                    if (rating != null)
                    {
                        rating.UpVotes += 1;
                    }
                    db.SaveChanges();
                    break;

                case VoteType.Down:
                    if (rating != null)
                    {
                        rating.DownVotes += 1;
                    }
                    db.SaveChanges();
                    break;

                default:
                    return(null);
                }

                var userVote = new UserVote {
                    Rating = rating, User = user, VoteType = voteType
                };
                db.UserVotes.Add(userVote);
                db.SaveChanges();


                return(user);
            });
        }
        private static async Task Seed(DatabaseContext databaseContext)
        {
            Console.WriteLine("Start of seed");
            Address[] addresses =
            {
                new Address {
                    street  = "Solvgade 1, 3tv",
                    city    = "Horsens",
                    zipCode = 8700,
                },
            };
            foreach (var address in addresses)
            {
                databaseContext.addresses.Add(address);
            }
            Console.WriteLine("2");

            BankInfo[] bankInfos =
            {
                new BankInfo {
                    cardNumber = 1234123412341234,
                    cardHolder = "Pawel Skrzypkowski"
                },
            };
            foreach (var bankInfo in bankInfos)
            {
                databaseContext.bankInfos.Add(bankInfo);
            }
            Console.WriteLine("3");


            Account[] acs =
            {
                new Account {
                    username = "******",
                    password = "******",
                    email    = "*****@*****.**",
                },
            };

            foreach (var account in acs)
            {
                databaseContext.accounts.Add(account);
            }
            Console.WriteLine("4");

            Category[] categories =
            {
                new Category()
                {
                    categoryName = "Italian",
                },
                new Category()
                {
                    categoryName = "Greek",
                },
            };

            foreach (var cat in categories)
            {
                databaseContext.categories.Add(cat);
            }
            Console.WriteLine("5");


            Recipe[] recipes =
            {
                new Recipe()
                {
                    recipeName   = "Arrabbiata",
                    recipeId     = 1,
                    description  = "Arrabbiata sauce, or sugo all'arrabbiata in Italian, is a spicy sauce for pasta made from garlic, tomatoes, and dried red chili peppers cooked in olive oil. The sauce originates from the Lazio region, around Rome. Arrabbiata literally means 'angry' in Italian; the name of the sauce refers to the spiciness of the chili peppers.",
                    instructions = "Sauté the crushed red pepper flakes: Heat the butter (or olive oil) in a large saucepan or deep sauté pan.  Add the crushed red pepper flakes and sauté for about 2 minutes, to help toast and bring out their flavor.\nAdd onion and garlic: Add in the onions and sauté until softened, followed by the garlic.\nAdd tomatoes:  Then add in the cans of whole tomatoes, juices included.  And as they begin to heat up, use a wooden spoon or a potato masher to carefully break up the tomatoes.  (Just wear an apron so that those juices inside of the tomatoes don’t accidentally splatter you!)\nSimmer: Continue heating the sauce until it comes to a simmer.  Then reduce heat to medium (or medium-low) to maintain a low simmer, and let the sauce cook for about 30 minutes, or until it reaches your desired consistency.\nStir in the basil, salt and pepper.  Then taste the sauce, and season with any extra salt, pepper and/or crushed red pepper flakes as needed.\nServe warm.  Or let the sauce cool and then refrigerate it in a sealed container for up to 4 days.",
                    cookingTime  = 40,
                    imageName    = "Arrabiata.jpg"
                },

                new Recipe()
                {
                    recipeName   = "Pizza",
                    recipeId     = 2,
                    description  = "Pizza, dish of Italian origin consisting of a flattened disk of bread dough topped with some combination of olive oil, oregano, tomato, olives, mozzarella or other cheese, and many other ingredients, baked quickly—usually, in a commercial setting, using a wood-fired oven heated to a very high temperature—and served hot.",
                    instructions = "Add warm water to the bowl of a stand mixer with the dough attachment, and sprinkle the yeast on top of the water.  Give the yeast a quick stir to mix it in with the water.  Then let it sit for 5-10 minute until the yeast is foamy.\nTurn the mixer onto low speed, and add gradually flour, honey, olive oil and salt.  Increase speed to medium-low, and continue mixing the dough for 5 minutes.\nRemove dough from the mixing bowl, and use your hands to shape it into a ball.  Grease the mixing bowl (or a separate bowl) with olive oil or cooking spray, then place the dough ball back in the bowl and cover it with a damp towel.  Place in a warm location (I set mine by the window) and let it rise for 30-45 minutes until the dough has nearly doubled in size.\nPreheat oven to 450 degrees F.  Turn the dough onto a floured surface, and roll the dough into a 12- to 14-inch round for a thick-crusted pizza.  (Or cut the dough in half, and roll it into two 12-inch rounds for two thin crust pizzas.)  Sprinkle a baking sheet or pizza stone evenly with the cornmeal, then place the dough on the baking sheet.\nTop the dough with your desired sauce and toppings.  (And for extra-golden crust, brush the crust with an extra few teaspoons of olive oil or butter.)\nFor thick crust, bake for 16-18 minutes, or until the crust is golden brown and the toppings are melted and cooked.  For the (two) thin crusts, bake for 14-16 minutes, or until the crust is golden brown and the toppings are melted and cooked.\nSlice and serve pizza warm.",
                    cookingTime  = 75,
                    imageName    = "Pizza.jpeg"
                },
            };
            foreach (var rec in recipes)
            {
                databaseContext.recipes.Add(rec);
            }
            Console.WriteLine("6");

            Ingredient[] ingredients =
            {
                new Ingredient()
                {
                    ingredientId   = 1,
                    ingredientName = "Garlic",
                    number         = 3,
                    unitType       = "cloves"
                },
                new Ingredient()
                {
                    ingredientId   = 2,
                    ingredientName = "Pasta",
                    number         = 0.5,
                    unitType       = "kg"
                }
            };

            foreach (var ing in ingredients)
            {
                databaseContext.ingredients.Add(ing);
            }
            Console.WriteLine("8");

            databaseContext.SaveChanges();

            Shop[] shops =
            {
                new Shop {
                    shopId      = 1,
                    shopName    = "Lidl",
                    shopAddress = addresses[0]
                },
            };

            foreach (var shop in shops)
            {
                databaseContext.shops.Add(shop);
            }
            Console.WriteLine("9");

            ShopIngredient[] shopIngredients =
            {
                new ShopIngredient()
                {
                    id       = 1,
                    name     = "Garlic",
                    price    = 3,
                    amount   = 3,
                    unitType = "cloves"
                },
                new ShopIngredient()
                {
                    id       = 2,
                    name     = "Pasta",
                    price    = 2,
                    amount   = 0.2,
                    unitType = "kg"
                },
            };

            foreach (var shoping in shopIngredients)
            {
                databaseContext.shopIngredients.Add(shoping);
            }
            Console.WriteLine("10");

            databaseContext.SaveChanges();

            Account steve = await databaseContext.accounts.FirstAsync(s => s.username.Equals("Jannik"));

            Address tek = await databaseContext.addresses.FirstAsync(c => c.street.Equals("Solvgade 1, 3tv"));

            AccountAddress sc = new AccountAddress()
            {
                address = tek,
                account = steve
            };

            steve.AccountAddresses = new List <AccountAddress>();
            steve.AccountAddresses.Add(sc);
            databaseContext.Update(steve);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Account steve2 = await databaseContext.accounts.FirstAsync(s => s.username.Equals("Jannik"));

            BankInfo bankInfo2 = await databaseContext.bankInfos.FirstAsync(c => c.cardNumber == 1234123412341234);

            AccountBankInfo sc2 = new AccountBankInfo()
            {
                account  = steve2,
                bankInfo = bankInfo2
            };

            steve.AccountBankInfos = new List <AccountBankInfo>();
            steve.AccountBankInfos.Add(sc2);
            databaseContext.Update(steve2);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //Connecting ingredients with recipes

            Recipe steve1 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 1);

            Ingredient tek1 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 1);

            IngredientRecipe sc1 = new IngredientRecipe()
            {
                ingredient = tek1,
                recipe     = steve1
            };

            steve1.IngredientRecipes = new List <IngredientRecipe>();
            steve1.IngredientRecipes.Add(sc1);
            databaseContext.Update(steve1);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Recipe steve3 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 1);

            Category bankInfo3 = await databaseContext.categories.FirstAsync(c => c.categoryName.Equals("Italian"));

            RecipeCategory sc3 = new RecipeCategory()
            {
                recipe   = steve3,
                category = bankInfo3
            };

            steve3.RecipeCategories = new List <RecipeCategory>();
            steve3.RecipeCategories.Add(sc3);
            databaseContext.Update(steve3);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();


            //connecting second recipe
            Recipe steve5 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2);

            Ingredient tek5 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 1);

            IngredientRecipe sc5 = new IngredientRecipe()
            {
                ingredient = tek5,
                recipe     = steve5
            };

            steve5.IngredientRecipes = new List <IngredientRecipe>();
            steve5.IngredientRecipes.Add(sc5);
            databaseContext.Update(steve5);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //adding second ingredient
            Recipe steve7 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2);

            Ingredient tek7 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 2);

            IngredientRecipe sc7 = new IngredientRecipe()
            {
                ingredient = tek7,
                recipe     = steve7
            };

            if (steve7.IngredientRecipes == null)
            {
                steve7.IngredientRecipes = new List <IngredientRecipe>();
            }
            steve7.IngredientRecipes.Add(sc7);
            databaseContext.Update(steve7);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Recipe steve6 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2);

            Category bankInfo6 = await databaseContext.categories.FirstAsync(c => c.categoryName.Equals("Greek"));

            RecipeCategory sc6 = new RecipeCategory()
            {
                recipe   = steve6,
                category = bankInfo6
            };

            steve6.RecipeCategories = new List <RecipeCategory>();
            steve6.RecipeCategories.Add(sc6);
            databaseContext.Update(steve6);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //shops


            //adding shopingredients
            Shop shop1 = await databaseContext.shops.FirstAsync(s => s.shopId == 1);

            ShopIngredient shopIngredient1 = await databaseContext.shopIngredients.FirstAsync(c => c.id == 1);

            ShopVare ss1 = new ShopVare()
            {
                shop           = shop1,
                shopIngredient = shopIngredient1
            };

            if (shop1.shopVares == null)
            {
                shop1.shopVares = new List <ShopVare>();
            }
            shop1.shopVares.Add(ss1);
            databaseContext.Update(shop1);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Shop shop2 = await databaseContext.shops.FirstAsync(s => s.shopId == 1);

            ShopIngredient shopIngredient2 = await databaseContext.shopIngredients.FirstAsync(c => c.id == 2);

            ShopVare ss2 = new ShopVare()
            {
                shop           = shop2,
                shopIngredient = shopIngredient2
            };

            if (shop2.shopVares == null)
            {
                shop2.shopVares = new List <ShopVare>();
            }
            shop2.shopVares.Add(ss2);
            databaseContext.Update(shop2);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //update categories in recipes
            Recipe          recipeUp1    = recipes[0];
            Recipe          recipeUp2    = recipes[1];
            List <Category> categoriesUp = await databaseContext.categories.ToListAsync();

            recipeUp1.category = categoriesUp[0];
            recipeUp2.category = categoriesUp[1];
            databaseContext.recipes.Update(recipeUp1);
            databaseContext.recipes.Update(recipeUp2);
            await databaseContext.SaveChangesAsync();

            Console.WriteLine("Finished seeding");
        }
        //lägger till ett recept
        public Recipe AddRecipe(string name, List<List<object>> ingredients)
        {
            if (!Regex.IsMatch(name, @"^[a-zA-Z ]+$"))
            {
                errorMessage = "Var god fyll i ett receptnamn (endast bokstäver)";
                throw new ArgumentException();
            }
            if (!ingredients.Any())
            {
                errorMessage = "Var god lägg till minst 1 ingrediens";
                throw new ArgumentException();
            }
            try
            {
                CreateMissingIngredients(ingredients);
            }
            catch (InvalidOperationException)
            {
                //felmedelandet = stack trace från createMissingIngredients();
                throw new ArgumentException();
            }

            Recipe newRecipe = new Recipe { recipeName = name };
            thDb.Recipe.Add(newRecipe);

            try
            {
                thDb.SaveChanges();
            }
            catch (DbUpdateException)
            {
                errorMessage = "Recept finns redan i databas, välj ett annat namn";
                thDb.Recipe.Remove(newRecipe);
                throw new ArgumentException();
            }

            foreach (List<object> l in ingredients)
            {
                IngredientRecipe iR = new IngredientRecipe { recipeName = name, ingredientName = (l[0] as string).ToLower(), amount = (int)l[1], unit = l[2] as string };
                try
                {
                    thDb.IngredientRecipe.Add(iR);
                    thDb.SaveChanges();
                }
                catch(DbUpdateException)
                {
                    errorMessage = "Var god gruppera ingredienserna";
                    thDb.IngredientRecipe.Remove(iR);
                    thDb.Recipe.Remove(newRecipe);
                    thDb.SaveChanges();
                    throw new ArgumentException();
                }

            }
            return newRecipe;
        }