Files
blazor-saas-hrm/Features/Organization/Employee/Cqrs/DeleteEmployeeIncomeByIdHandler.cs
T
2026-07-21 14:22:06 +07:00

27 lines
980 B
C#

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;
}
}