Improve Publisher
This commit is contained in:
@@ -1,11 +1,41 @@
|
||||
using Bitvault.Data;
|
||||
using HarfBuzzSharp;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
||||
IPublisher publisher) :
|
||||
IHandler<CreateEventArgs<ItemConfiguration>, bool>
|
||||
@@ -30,7 +60,7 @@ public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFa
|
||||
if (result is not null)
|
||||
{
|
||||
Item item = new() { Id = result.Entity.Id, Name = configuration.Name };
|
||||
await publisher.Publish(Activated.As(item), cancellationToken);
|
||||
publisher.Publish(Activated.As(item), cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user