public AddIngredientsViewModel(AddIngredients addIngredientsOpen, tblRecipe recipeCreated) { addIngredientsView = addIngredientsOpen; recipe = recipeCreated; Ingredient = new tblIngredient(); ingredient.recipeId = recipeCreated.recipeId; }
public bool FetchIngredients(AddIngredients data) { if (data != null) { Ingredients ingredients = new Ingredients(); ingredients.MainComponent = data.ingredientsName; ingredients.MainImage = data.ingredientsImage; _db.Ingredients.Add(ingredients); _db.SaveChanges(); return(true); } return(false); }
private void SaveExecute() { try { recipe.type = selectedType; service.AddRecipe(recipe); tblRecipe addedRecipe = service.AddRecipe(recipe); MessageBox.Show("Recipe has been added. Add ingredients for this recipe"); addRecipe.Close(); AddIngredients addIngredients = new AddIngredients(addedRecipe); addIngredients.ShowDialog(); isUpdated = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public IActionResult AddIngredients([FromBody] AddIngredients model) { try { if (!ModelState.IsValid) { return(Json(new { status = "Error" })); } var newIngredient = new RecipeIngredients() { RecipeId = model.RecipeId, Name = model.Name, Quantity = model.Quantity }; myContext.RecipeIngredients.Add(newIngredient); myContext.SaveChanges(); return(Json(new { status = "Success" })); } catch (System.Exception) { throw; } }