Refactoring some Repo methods to not throw exception

This commit is contained in:
Francesco Lorenzo D'Amico
2025-05-20 14:23:46 +02:00
parent 8d9eb4b364
commit 0c3b7380c5
2 changed files with 4 additions and 3 deletions
@@ -19,6 +19,6 @@
Task<IEnumerable<Recipe>> SearchInRecipesAndIngredients(string searchterm);
Task DeleteRecipeAsync(Guid recipeId);
Task<bool> DeleteRecipeAsync(Guid recipeId);
}
}
@@ -184,13 +184,13 @@
.ToListAsync();
}
public async Task DeleteRecipeAsync(Guid recipeId)
public async Task<bool> DeleteRecipeAsync(Guid recipeId)
{
var recipe = await GetRecipeByIdAsync(recipeId);
if (recipe == null)
{
throw new InvalidDataException($"Rezept mit ID {recipeId} nicht gefunden.");
return false;
}
if (recipe.RecipeIngredients != null && recipe.RecipeIngredients.Any())
@@ -224,6 +224,7 @@
_context.Recipes.Remove(recipe);
await _context.SaveChangesAsync();
return true;
}
}
}