WIP: Item counts

This commit is contained in:
TheXamlGuy
2024-06-11 22:32:14 +01:00
parent 0fecdef1fe
commit ec7d6611a1
28 changed files with 205 additions and 74 deletions
+9 -11
View File
@@ -1,12 +1,11 @@
using Wallet.Data;
using Microsoft.EntityFrameworkCore;
using System.Threading;
using Toolkit.Foundation;
using Toolkit.Foundation;
namespace Wallet;
public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
IDbContextFactory<WalletContext> dbContextFactory) :
ICache<Item<(Guid, string)>> cache,
IMediator mediator,
IPublisher publisher) :
INotificationHandler<UnarchiveEventArgs<Item>>
{
public async Task Handle(UnarchiveEventArgs<Item> args)
@@ -17,12 +16,11 @@ public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decora
{
(Guid id, string name) = item.Value;
using WalletContext context = await dbContextFactory.CreateDbContextAsync();
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
{
result.State = 0;
await context.SaveChangesAsync();
}
await mediator.Handle<UpdateEventArgs<(Guid, int)>,
bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
cache.Add(item);
publisher.Publish(Changed.As(item));
}
}
catch