Allow the Mediator to be subscribed to and therefore handled

This commit is contained in:
TheXamlGuy
2024-05-15 19:28:07 +01:00
parent 98896267dc
commit 2c14001c26
7 changed files with 100 additions and 95 deletions
+34
View File
@@ -0,0 +1,34 @@
using Bitvault.Data;
using Microsoft.EntityFrameworkCore;
using Toolkit.Foundation;
namespace Bitvault;
public class ArchiveItemHandler(IValueStore<Item> valueStore,
IDbContextFactory<ContainerDbContext> dbContextFactory) :
INotificationHandler<ArchiveEventArgs<Item>>
{
public async Task Handle(ArchiveEventArgs<Item> args)
{
try
{
if (valueStore.Value is Item item)
{
await Task.Run(async () =>
{
using ContainerDbContext context = await dbContextFactory.CreateDbContextAsync();
if (await context.FindAsync<ItemEntry>(item.Id) is ItemEntry result)
{
result.State = 3;
await context.SaveChangesAsync();
}
});
}
}
catch
{
}
}
}