public MyResponse UpdateIngredient(Ingredient ingredient, string userId) { MyResponse validateResult = ValidateUpdateIngredient(ingredient, userId); if (validateResult.IsSuccess()) { _ingredientsRepository.PutIngredient(ingredient); } return(validateResult); }
private void UpdateOrAddIngredientsToRecipe(Ingredient[] ingredientsFromRequest, List <Ingredient> dbIngredients, int recipeId) { foreach (Ingredient i in ingredientsFromRequest) { i.RecipeId = recipeId; if (dbIngredients.Where(dbI => dbI.Id == i.Id).Any()) { _ingredientsRepository.PutIngredient(i); } else { i.Id = 0; _ingredientsRepository.PostIngredient(i); } } }