public async Task UpdateRecipeAsync(UpdateRecipeCommand cmd) { var recipe = await _context.Recipes .Include(r => r.Ingridients) .FirstOrDefaultAsync(r => r.RecipeId == cmd.Id); if (recipe == null) { throw new Exception($"Unable to find recipe with ID {cmd.Id}"); } cmd.UpdateRecipe(recipe); await _context.SaveChangesAsync(); }
/// <summary> /// Updateds an existing recipe /// </summary> /// <param name="cmd"></param> /// <returns>The id of the new recipe</returns> public async Task UpdateRecipe(UpdateRecipeCommand cmd) { var recipe = await _context.Recipes.FindAsync(cmd.Id); if (recipe == null) { throw new Exception("Unable to find the recipe"); } if (recipe.IsDeleted) { throw new Exception("Unable to update a deleted recipe"); } cmd.UpdateRecipe(recipe); await _context.SaveChangesAsync(); }
/// <summary> /// Updateds an existing recipe /// </summary> /// <param name="cmd"></param> /// <returns>The id of the new recipe</returns> public void UpdateRecipe(UpdateRecipeCommand cmd) { var recipe = _context.Recipes.Find(cmd.Id); if (recipe == null) { throw new Exception("Unable to find the recipe"); } if (recipe.IsDeleted) { throw new Exception("Unable to update a deleted recipe"); } cmd.UpdateRecipe(recipe); _context.SaveChanges(); }