public void AddFavourite(Recipe recipe, Favourite favourite) { if (favourite.FavouriteID == 0) { context.Favourites.Add(favourite); } else { RecipeViewModel dbEntry = context.RecipesVM .FirstOrDefault(r => r.recipeItem.RecipeId == recipe.RecipeId); Favourite dbEntry2 = context.Favourites .FirstOrDefault(r => r.RecipeId == recipe.RecipeId); if (dbEntry != null) { dbEntry.recipeItem.Name = favourite.recipeName; dbEntry.recipeItem.RecipeId = recipe.RecipeId; dbEntry2.FavouriteID = favourite.FavouriteID; dbEntry2.UserName = favourite.UserName; } } context.SaveChanges(); }
public static void AddFavToRepo(Favourite newFavourite) { FavouritesList.Add(newFavourite); }