using Wallet.Data; using Microsoft.EntityFrameworkCore; using System.Text.Json; using System.Text; using Toolkit.Foundation; namespace Wallet; public class UpdateItemHander(IDbContextFactory dbContextFactory) : IHandler>, bool> { public async Task Handle(UpdateEventArgs> args, CancellationToken cancellationToken) { if (args.Value is Item<(Guid, string, ItemConfiguration)> item) { (Guid id, string name, ItemConfiguration configuration) = item.Value; try { using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken); ItemEntry? result = result = await context.Set().FindAsync([id], cancellationToken); if (result is not null) { string content = JsonSerializer.Serialize(configuration); result.Blobs.Add(new() { Data = Encoding.UTF8.GetBytes(content), DateTime = DateTime.Now, Type = 0, }); result.Name = name; await context.SaveChangesAsync(cancellationToken); } if (result is not null) { return true; } } catch { } } return false; } }