This commit is contained in:
lumijiez
2025-06-20 14:54:19 +03:00
parent b418607a89
commit 92bdb8444b
46 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
using MediatR;
namespace Imprink.Application.Domains.Products;
public class DeleteProductCommand : IRequest<bool>
{
public Guid Id { get; set; }
}
public class DeleteProductHandler(IUnitOfWork unitOfWork) : IRequestHandler<DeleteProductCommand, bool>
{
public async Task<bool> Handle(DeleteProductCommand request, CancellationToken cancellationToken)
{
await unitOfWork.BeginTransactionAsync(cancellationToken);
try
{
var exists = await unitOfWork.ProductRepository.ExistsAsync(request.Id, cancellationToken);
if (!exists)
{
await unitOfWork.RollbackTransactionAsync(cancellationToken);
return false;
}
await unitOfWork.ProductRepository.DeleteAsync(request.Id, cancellationToken);
await unitOfWork.CommitTransactionAsync(cancellationToken);
return true;
}
catch
{
await unitOfWork.RollbackTransactionAsync(cancellationToken);
throw;
}
}
}