WIP
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
using Bitvault.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ConfirmItemHandler(IMediator mediator,
|
||||
IDbContextFactory<ContainerDbContext> dbContextFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
public class EditItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<EditEventArgs<(int, ItemConfiguration)>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(ConfirmEventArgs<Item> args,
|
||||
public async Task<bool> Handle(EditEventArgs<(int, ItemConfiguration)> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await mediator.Handle<ConfirmEventArgs<Item>, bool>(args);
|
||||
//if (args.Value is ItemConfiguration configuration)
|
||||
//{
|
||||
// try
|
||||
@@ -29,9 +27,6 @@ public class ConfirmItemHandler(IMediator mediator,
|
||||
|
||||
// if (result is not null)
|
||||
// {
|
||||
// Item item = new() { Id = result.Entity.Id, Name = configuration.Name };
|
||||
// publisher.Publish(Activated.As(item), cancellationToken);
|
||||
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
@@ -43,9 +38,54 @@ public class ConfirmItemHandler(IMediator mediator,
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
public class CreateItemHander(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||
IHandler<CreateEventArgs<ItemConfiguration>, (bool, int)>
|
||||
{
|
||||
public async Task<(bool, int)> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ItemHeaderConfiguration? headerConfiguration = await mediator.Handle<ConfirmEventArgs<Item>, ItemHeaderConfiguration>(args);
|
||||
if (args.Value is ItemConfiguration configuration)
|
||||
{
|
||||
try
|
||||
{
|
||||
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||
EntityEntry<ItemEntry>? result = null;
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
}, cancellationToken);
|
||||
|
||||
if (result is not null)
|
||||
{
|
||||
return (false, -1);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (false, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmItemHandler(IMediator mediator,
|
||||
IValueStore<Item> valueStore,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
(bool result, int index) result = await mediator.Handle<CreateEventArgs<ItemConfiguration>,
|
||||
(bool, int)>(new CreateEventArgs<ItemConfiguration>(new ItemConfiguration()));
|
||||
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
ItemHeaderConfiguration>(args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user