Add ability to fully delete items from the DB

This commit is contained in:
TheXamlGuy
2024-06-23 09:58:19 +01:00
parent 95de9d187f
commit db20ee15cc
18 changed files with 98 additions and 22 deletions
+26
View File
@@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore;
using Toolkit.Foundation;
using Wallet.Data;
namespace Wallet;
public class DeleteItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<DeleteEventArgs<Item<Guid>>, bool>
{
public async Task<bool> Handle(DeleteEventArgs<Item<Guid>> args,
CancellationToken cancellationToken)
{
if (args.Sender is Item<Guid> item)
{
Guid id = item.Value;
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
{
context.Items.Remove(result);
await context.SaveChangesAsync(cancellationToken);
}
}
return false;
}
}