public async Task AddRecipeAsync(Recipe recipe, Category category, List <Tag> tags)
        {
            var dbContext = new TasteItDbEntities();

            dbContext.Recipes.Add(recipe);
            await dbContext.SaveChangesAsync();

            Recipe currentRecipe = await dbContext.Recipes.FirstOrDefaultAsync(r => r.name == recipe.name);


            if (currentRecipe != null)
            {
                //foreach (var category in categories)
                //{
                //    dbContext.Have_category.Add(new Have_category { id_c = category.id_c, id_r = currentRecipe.id_r });
                //}
                dbContext.Have_category.Add(new Have_category {
                    id_c = category.id_c, id_r = currentRecipe.id_r
                });

                foreach (var tag in tags)
                {
                    dbContext.Have_tags.Add(new Have_tags {
                        id_t = tag.id_t, id_r = currentRecipe.id_r
                    });
                }
            }

            await dbContext.SaveChangesAsync();
        }
Exemple #2
0
        public async Task AddTagAsync(Tag tag)
        {
            var dbContext = new TasteItDbEntities();

            dbContext.Tags.Add(tag);
            await dbContext.SaveChangesAsync();
        }
        public async Task AddToFavourites(User user, Recipe recipe)
        {
            var dbContext = new TasteItDbEntities();

            dbContext.Have_favourites.Add(new Have_favourites {
                id_u = user.id_u, id_r = recipe.id_r
            });

            await dbContext.SaveChangesAsync();
        }
        public async Task AddRecipeAsync(Recipe recipe, Category category, Tag tag)
        {
            var dbContext = new TasteItDbEntities();

            dbContext.Recipes.Add(recipe);
            await dbContext.SaveChangesAsync();

            Recipe currentRecipe = await dbContext.Recipes.FirstOrDefaultAsync(r => r.name == recipe.name);

            if (currentRecipe != null)
            {
                dbContext.Have_category.Add(new Have_category {
                    id_c = category.id_c, id_r = currentRecipe.id_r
                });
                dbContext.Have_tags.Add(new Have_tags {
                    id_t = tag.id_t, id_r = currentRecipe.id_r
                });
            }


            await dbContext.SaveChangesAsync();
        }
Exemple #5
0
 public async Task AddUserAsync(User user)
 {
     dbContext = new TasteItDbEntities();
     dbContext.Users.Add(user);
     await dbContext.SaveChangesAsync();
 }