Generator Changes at 11/16/2025 12:48:45 AM +03:30
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Domain.Events;
|
||||
namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract;
|
||||
public class DeleteContractCommandHandler : IRequestHandler<DeleteContractCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public DeleteContractCommandHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteContractCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.Contracts
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Contract), request.Id);
|
||||
entity.IsDeleted = true;
|
||||
_context.Contracts.Update(entity);
|
||||
entity.AddDomainEvent(new DeleteContractEvent(entity));
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user