Unlink child suggestions and clear votes on delete
This commit is contained in:
@@ -111,6 +111,14 @@ public static class SuggestEndpoints
|
|||||||
if (suggestion == null)
|
if (suggestion == null)
|
||||||
return Results.NotFound(new { error = "Suggestion not found." });
|
return Results.NotFound(new { error = "Suggestion not found." });
|
||||||
|
|
||||||
|
// Break any links that pointed at this suggestion
|
||||||
|
await db.Suggestions
|
||||||
|
.Where(s => s.ParentSuggestionId == suggestion.Id)
|
||||||
|
.ExecuteUpdateAsync(s => s.SetProperty(x => x.ParentSuggestionId, (int?)null));
|
||||||
|
|
||||||
|
// Remove votes for this suggestion to avoid orphaned vote rows or FK errors
|
||||||
|
await db.Votes.Where(v => v.SuggestionId == suggestion.Id).ExecuteDeleteAsync();
|
||||||
|
|
||||||
db.Suggestions.Remove(suggestion);
|
db.Suggestions.Remove(suggestion);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
return Results.NoContent();
|
return Results.NoContent();
|
||||||
|
|||||||
Reference in New Issue
Block a user