/// <summary> /// Adds a RecipeItem to the database, assigns it to a product. /// A product will be marked as set. From this moment forward it can't be changed without reloading the View(Model). /// </summary> /// <param name="item">The RecipeItem (created by the view) that has to be added.</param> private void AddRecipeItem(RecipeItem item) { IsProductNotSet = false; ProductRecipeItems.Add(SelectedRecipeItem); if (ActionToTake == "edit") { _recipeRepo.AddRecipe(SelectedRecipeItem); } Data.RecipeItem tempRecipeItem = SelectedRecipeItem; SelectedRecipeItem = new RecipeItem(); SelectedRecipeItem.Product = tempRecipeItem.Product; }
public IActionResult PostRecipe(Recipe recipe) { if (RecipeExists(recipe.Id)) { _logger.LogWarning($"Recipe with id: {recipe.Id} already exists."); return(Conflict()); } _recipeRepo.AddRecipe(recipe); _recipeRepo.SaveChanges(); _logger.LogInformation($"Recipe with id: {recipe.Id} has been added."); return(CreatedAtAction(nameof(Get), new { id = recipe.Id }, recipe)); }
public ActionResult <Recipe> Post([FromBody] Recipe recipe) { return(new JsonResult(_recipeRepo.AddRecipe(recipe))); }
public ViewResult InsertPage(Recipe recipe) { IRecipeRepo.AddRecipe(recipe); return(View("DataPage", IRecipeRepo.Recipes)); }