public async Task <IActionResult> SetIngredientsInRecipe(SetIngredientsViewModel entry) { Recipe recipe = await _context.Recipe.FirstOrDefaultAsync(r => r.Id == entry.RecipeId); if (recipe == null) { return(NotFound()); } if (ModelState.IsValid) { foreach (int ingId in entry.IngredientIds) { RecipeIngredient recipeIngredient = await _context.RecipeIngredient .FirstOrDefaultAsync(r => r.RecipeId == entry.RecipeId && r.IngredientId == ingId); if (recipeIngredient == null) { recipeIngredient = new RecipeIngredient { RecipeId = entry.RecipeId, IngredientId = ingId }; _context.Add(recipeIngredient); } } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { rTitle = recipe.Title })); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] Chef chef) { if (ModelState.IsValid) { _context.Add(chef); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(chef)); }
public async Task <IActionResult> Create([Bind("Id,Name,ImageUrl,CaloriesPerItem,ProteinsPerItem,VitaminsPerItem,IngredientFact")] Ingredient ingredient) { if (ModelState.IsValid) { _context.Add(ingredient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,PrepareTime,ImageUrl,Type,ChefId")] Recipe recipe) { if (ModelState.IsValid) { _context.Add(recipe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ChefId"] = new SelectList(_context.Set <Chef>(), "Id", "FirstName", recipe.ChefId); return(View(recipe)); }