Files
Walleby/Bitvault/UnarchiveItemHandler.cs
T
2024-06-06 20:42:23 +01:00

32 lines
928 B
C#

using Bitvault.Data;
using Microsoft.EntityFrameworkCore;
using System.Threading;
using Toolkit.Foundation;
namespace Bitvault;
public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
IDbContextFactory<LockerContext> dbContextFactory) :
INotificationHandler<UnarchiveEventArgs<Item>>
{
public async Task Handle(UnarchiveEventArgs<Item> args)
{
try
{
if (decoratorService.Service is Item<(Guid, string)> item)
{
(Guid id, string name) = item.Value;
using LockerContext context = await dbContextFactory.CreateDbContextAsync();
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
{
result.State = 0;
await context.SaveChangesAsync();
}
}
}
catch
{
}
}
}