internal async Task <int> UpdateAndSaveCookBook(CookBooksEditViewModel viewModel) { CookBook cookBook = await repository.GetAsync(viewModel.CookBookId); cookBook = UpdateCookBookWithViewModelData(cookBook, viewModel); repository.Update(cookBook); return(await repository.SaveChangesAsync()); }
public Recipe(RecipesCreateViewModel viewModel, string ownerId, CookBook cookBook) { RecipeName = viewModel.RecipeName; Ingredients = viewModel.Ingredients; Instructions = viewModel.Instructions; IsPublic = viewModel.IsPublic; OwnerId = ownerId; CookBooksContainingRecipe.Add(cookBook); ImageReference = viewModel.ImageReference; Description = viewModel.Description; }
//Returns success string to be displayed to user internal string RemoveRecipeFromCookBook(int recipeId, int cookbookId) { CookBook cookBook = GetCookbookById(cookbookId, context); Recipe recipe = GetRecipeById(recipeId, context); recipe.CookBooksContainingRecipe.Remove(cookBook); cookBook.Recipes.Remove(recipe); context.Entry(cookBook).State = EntityState.Modified; context.Entry(recipe).State = EntityState.Modified; string message = recipe.RecipeName + " removed!"; context.SaveChanges(); context.Dispose(); return(message); }
internal async Task <int> RemoveRecipeFromCookBookAndSave(int cookBookId, int recipeId) { CookBook cookBook = await repository.GetAsync(cookBookId); List <Recipe> newRecipeList = new List <Recipe>(); foreach (var recipe in cookBook.Recipes) { if (recipe.RecipeId != recipeId) { newRecipeList.Add(recipe); } } cookBook.Recipes = newRecipeList; repository.Update(cookBook); return(await repository.SaveChangesAsync()); }
internal string AddRecipeToCookBook(Recipe recipe, CookBook cookbook, ApplicationDbContext context) { string message = recipe.RecipeName + " could not be saved to " + cookbook.CookBookName + " at this time."; try { recipe.CookBooksContainingRecipe.Add(cookbook); cookbook.Recipes.Add(recipe); context.Entry(cookbook).State = EntityState.Modified; context.Entry(recipe).State = EntityState.Modified; context.SaveChanges(); context.Dispose(); return(recipe.RecipeName + " saved!"); } catch (Exception e) { return(message); } }
public CookBook UpdateCookBookWithViewModelData(CookBook cookBook, CookBooksEditViewModel viewModel) { cookBook.CookBookName = viewModel.CookBookName; cookBook.CookBookDescription = viewModel.CookBookDescription; return(cookBook); }
internal static CookBook SortRecipesInCookBook(CookBook cookBook) { SortRecipes(cookBook.Recipes); return(cookBook); }