public async Task <Recipe> EditRecipe(RecipeFormModel recipeModel) { var currentRecipe = await GetRecipeNoTracking(recipeModel.Id); if (recipeModel.Title.Equals(currentRecipe.Title) && recipeModel.Description == currentRecipe.Description && recipeModel.Ingredients.Equals(currentRecipe.Ingredients) && recipeModel.Directions.Equals(currentRecipe.Directions)) { return(currentRecipe); } await _context.Revisions.AddAsync(new RecipeRevision() { RecipeId = currentRecipe.Id, DateModified = currentRecipe.DateLastUpdated ?? currentRecipe.DateCreated, Title = currentRecipe.Title, Description = currentRecipe.Description, Directions = currentRecipe.Directions, Ingredients = currentRecipe.Ingredients }); var recipe = recipeModel.Map(); recipe.DateCreated = currentRecipe.DateCreated; recipe.ParentRecipeId = currentRecipe.ParentRecipeId; recipe.DateLastUpdated = DateTime.Now; _context.Recipes.Update(recipe); await _context.SaveChangesAsync(); return(await GetRecipe(recipe.Id)); }
public async Task <IActionResult> PostRecipe(RecipeFormModel model) { var param = this.mapper.Map <RecipeInputModel>(model); var result = await this.recipesService.PostRecipe(param); return(RedirectToAction("Index", "Home")); }
public async Task <Recipe> AddRecipe(RecipeFormModel recipeModel) { var recipe = recipeModel.Map(); recipe.DateCreated = DateTime.Now; await _context.Recipes.AddAsync(recipe); await _context.SaveChangesAsync(); return(recipe); }
public async Task <IActionResult> Edit(RecipeFormModel recipeModel) { var recipe = await _recipeService.EditRecipe(recipeModel); return(RedirectToRoute(new RouteValueDictionary(new { action = "GetRecipe", controller = "Recipe", recipeId = recipe.Id }))); }
public async Task <RecipeModel> Edit(RecipeFormModel recipeModel) { var recipe = await _recipeService.EditRecipe(recipeModel); return(new RecipeModel().Map(recipe)); }