namespace Brizco.Repository.Handlers.Activity; public class DeleteActivityCommandHandler : IRequestHandler { private readonly IRepositoryWrapper _repositoryWrapper; public DeleteActivityCommandHandler(IRepositoryWrapper repositoryWrapper) { _repositoryWrapper = repositoryWrapper; } public async Task Handle(DeleteActivityCommand request, CancellationToken cancellationToken) { try { await _repositoryWrapper.BeginTransaction(cancellationToken); var task = await _repositoryWrapper.SetRepository() .TableNoTracking .FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); if (task == null) throw new AppException("Task not found", ApiResultStatusCode.NotFound); _repositoryWrapper.SetRepository() .Delete(task); await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken); return true; } catch (Exception ) { await _repositoryWrapper.RollBackAsync(cancellationToken); throw; } } }