Implemented the delete function for text elements

This commit is contained in:
tsommer committed 2022-07-23 21:21:48 +02:00
1 parent e762cfe21e
commit 71936e5dcf
2 files changed
+31 -1

No files matched your search

@@ -91,4 +91,23 @@ public static class TextElementProcessor
return updateException.ToProcessorResult<TextElement>();
}
}
// Deletes a text element:
public static async Task DeleteTextElement(int id)
{
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
var textElement = await db.TextElements.FirstAsync(n => n.Id == id);
// Remove the element from the database:
db.TextElements.Remove(textElement);
try
{
// Save the changes:
await db.SaveChangesAsync();
}
catch (DbUpdateException updateException)
{
}
}
}