public bool CreateFavoriteRecipe(FavoriteRecipeCreate model) { var entity = new FavoriteRecipe() { UserID = _userId, FavoriteList = model.FavoriteList, Recipes = model.Recipes }; using (var ctx = new ApplicationDbContext()) { ctx.FavoriteRecipes.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(FavoriteRecipeCreate favoriteRecipe) { if (!ModelState.IsValid) { return(View(favoriteRecipe)); } var service = FavoriteRecipeService(); if (service.CreateFavoriteRecipe(favoriteRecipe)) { TempData["SaveResult"] = "YAY to Favorite Recipes!!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "So Sad. No Favorite Recipe Created. Don't Give up!"); return(View(favoriteRecipe)); }