initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
||||
|
||||
public record DeleteEmployeeIncomeByIdRequest(string Id);
|
||||
|
||||
public record DeleteEmployeeIncomeByIdCommand(DeleteEmployeeIncomeByIdRequest Data) : IRequest<bool>;
|
||||
|
||||
public class DeleteEmployeeIncomeByIdHandler : IRequestHandler<DeleteEmployeeIncomeByIdCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteEmployeeIncomeByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteEmployeeIncomeByIdCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.EmployeeIncome
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.EmployeeIncome.Remove(entity);
|
||||
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user