We are confidence enough that the data will be saved to the db, so lets change how we update the UI, so instead of wating on the db call to complete, we will just update the UI while the db call is in progress

This commit is contained in:
TheXamlGuy
2024-05-22 20:13:50 +01:00
parent 0d7cb192d5
commit 9c8c7bf889
9 changed files with 46 additions and 55 deletions
+8 -6
View File
@@ -6,28 +6,30 @@ using Toolkit.Foundation;
namespace Bitvault;
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory) :
IHandler<CreateEventArgs<ItemConfiguration>, (bool, int, string?)>
IHandler<CreateEventArgs<(Guid, ItemConfiguration)>, bool>
{
public async Task<(bool, int, string?)> Handle(CreateEventArgs<ItemConfiguration> args,
public async Task<bool> Handle(CreateEventArgs<(Guid, ItemConfiguration)> args,
CancellationToken cancellationToken)
{
if (args.Value is ItemConfiguration configuration)
if (args.Value is (Guid id, ItemConfiguration configuration))
{
try
{
string? name = configuration.Name;
using ContainerDbContext context = dbContextFactory.CreateDbContext();
EntityEntry<ItemEntry>? result = null;
await Task.Run(async () =>
{
result = await context.AddAsync(new ItemEntry { Name = configuration.Name }, cancellationToken);
result = await context.AddAsync(new ItemEntry { Id = id, Name = name }, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
}, cancellationToken);
if (result is not null)
{
return (true, result.Entity.Id, result.Entity.Name);
return true;
}
}
catch
@@ -36,6 +38,6 @@ public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFa
}
}
return (false, -1, "");
return false;
}
}