Files
Walleby/Wallet/ItemChangedHandler.cs
T
2024-06-11 22:32:14 +01:00

23 lines
709 B
C#

using Toolkit.Foundation;
namespace Wallet;
public class ItemChangedHandler(IMediator mediator,
IPublisher publisher) :
INotificationHandler<ChangedEventArgs<Item<(Guid, string)>>>
{
public async Task Handle(ChangedEventArgs<Item<(Guid, string)>> args)
{
IReadOnlyCollection<(string, int)>? categoryCounts = await mediator.Handle<CountEventArgs<ItemCategory>,
IReadOnlyCollection<(string, int)>>(Count.As<ItemCategory>());
if (categoryCounts is { Count: > 0 } )
{
foreach ((string key, int count) in categoryCounts)
{
publisher.Publish(Notify.As(new Item<int>(count)), key);
}
}
}
}