Refactoring some Repo methods to not throw exception
This commit is contained in:
@@ -19,6 +19,6 @@
|
|||||||
|
|
||||||
Task<IEnumerable<Recipe>> SearchInRecipesAndIngredients(string searchterm);
|
Task<IEnumerable<Recipe>> SearchInRecipesAndIngredients(string searchterm);
|
||||||
|
|
||||||
Task DeleteRecipeAsync(Guid recipeId);
|
Task<bool> DeleteRecipeAsync(Guid recipeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,13 +184,13 @@
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteRecipeAsync(Guid recipeId)
|
public async Task<bool> DeleteRecipeAsync(Guid recipeId)
|
||||||
{
|
{
|
||||||
var recipe = await GetRecipeByIdAsync(recipeId);
|
var recipe = await GetRecipeByIdAsync(recipeId);
|
||||||
|
|
||||||
if (recipe == null)
|
if (recipe == null)
|
||||||
{
|
{
|
||||||
throw new InvalidDataException($"Rezept mit ID {recipeId} nicht gefunden.");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipe.RecipeIngredients != null && recipe.RecipeIngredients.Any())
|
if (recipe.RecipeIngredients != null && recipe.RecipeIngredients.Any())
|
||||||
@@ -224,6 +224,7 @@
|
|||||||
_context.Recipes.Remove(recipe);
|
_context.Recipes.Remove(recipe);
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user