Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public async Task AddTagAsync(Tag tag)
        {
            var dbContext = new TasteItDbEntities();

            dbContext.Tags.Add(tag);
            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
 public async Task AddUserAsync(User user)
 {
     dbContext = new TasteItDbEntities();
     dbContext.Users.Add(user);
     await dbContext.SaveChangesAsync();
 }