More edge cases

This commit is contained in:
TheXamlGuy
2024-05-26 14:51:25 +01:00
parent 859d16c85c
commit 307443e4ce
12 changed files with 59 additions and 56 deletions
+28
View File
@@ -0,0 +1,28 @@
using Bitvault.Data;
using Microsoft.EntityFrameworkCore;
using Toolkit.Foundation;
namespace Bitvault;
public class UpdateItemStateHandler(IDbContextFactory<ContainerDbContext> dbContextFactory) :
IHandler<UpdateEventArgs<(Guid, int)>, bool>
{
public async Task<bool> Handle(UpdateEventArgs<(Guid, int)> args,
CancellationToken cancellationToken)
{
if (args.Value is (Guid id, int state))
{
await Task.Run(async () =>
{
using ContainerDbContext context = await dbContextFactory.CreateDbContextAsync();
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
{
result.State = state;
await context.SaveChangesAsync();
}
}, cancellationToken);
}
return false;
}
}