initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Payroll.Payrolls.Cqrs;
|
||||
|
||||
public class DeletePayrollProcessByIdRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePayrollProcessByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
|
||||
public record DeletePayrollProcessByIdCommand(DeletePayrollProcessByIdRequest Data) : IRequest<DeletePayrollProcessByIdResponse>;
|
||||
|
||||
public class DeletePayrollProcessByIdHandler : IRequestHandler<DeletePayrollProcessByIdCommand, DeletePayrollProcessByIdResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeletePayrollProcessByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<DeletePayrollProcessByIdResponse> Handle(DeletePayrollProcessByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.PayrollProcess
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new NotFoundException("Payroll Process", request.Data.Id ?? string.Empty);
|
||||
}
|
||||
|
||||
_context.PayrollProcess.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new DeletePayrollProcessByIdResponse
|
||||
{
|
||||
Id = entity.Id
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user