public async Task AddTagAsync(Tag tag) { var dbContext = new TasteItDbEntities(); dbContext.Tags.Add(tag); await dbContext.SaveChangesAsync(); }
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(); }
public async Task <IEnumerable <Recipe> > FindByCategory(Category category) { var dbContext = new TasteItDbEntities(); Category current = await dbContext.Categories.FirstOrDefaultAsync(c => c.name == category.name); var list = current.Have_category.Select(f => f.id_r).ToList(); return(await dbContext.Recipes.AsNoTracking().Where(r => list.Contains(r.id_r)).ToListAsync()); }
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 <Tag> FindTag(Tag tag) { var dbContext = new TasteItDbEntities(); if (await dbContext.Tags.AnyAsync(t => t.name == tag.name)) { Tag current = await dbContext.Tags.FirstOrDefaultAsync(t => t.name == tag.name); return(current); } else { return(null); } }
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(); }
public async Task <IEnumerable <Tag> > GetTagsAsync() { var dbContext = new TasteItDbEntities(); return(await dbContext.Tags.AsNoTracking().ToListAsync()); }
public async Task AddUserAsync(User user) { dbContext = new TasteItDbEntities(); dbContext.Users.Add(user); await dbContext.SaveChangesAsync(); }
public async Task <IEnumerable <User> > GetUsersAsync() { dbContext = new TasteItDbEntities(); return(await dbContext.Users.AsNoTracking().ToListAsync()); }
public async Task <IEnumerable <Category> > GetCategoriesAsync() { var dbContext = new TasteItDbEntities(); return(await dbContext.Categories.AsNoTracking().ToListAsync()); }