using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Payroll.PayrollDetails.Cqrs; public class GetPayrollDetailListByProcessIdRequest { public string? PayrollProcessId { get; set; } } public class GetPayrollDetailListByProcessIdResponse { public string? Id { get; set; } public string? EmployeeId { get; set; } public string? EmployeeCode { get; set; } public string? EmployeeName { get; set; } public decimal BasicSalary { get; set; } public decimal TotalIncome { get; set; } public decimal TotalDeduction { get; set; } public decimal TakeHomePay { get; set; } } public record GetPayrollDetailListByProcessIdQuery(GetPayrollDetailListByProcessIdRequest Data) : IRequest>; public class GetPayrollDetailListByProcessIdHandler : IRequestHandler> { private readonly AppDbContext _context; public GetPayrollDetailListByProcessIdHandler(AppDbContext context) => _context = context; public async Task> Handle(GetPayrollDetailListByProcessIdQuery request, CancellationToken cancellationToken) { var data = await _context.PayrollDetail .Where(x => x.PayrollProcessId == request.Data.PayrollProcessId) .Select(x => new GetPayrollDetailListByProcessIdResponse { Id = x.Id, EmployeeId = x.EmployeeId, EmployeeCode = x.EmployeeCode, EmployeeName = x.EmployeeName, BasicSalary = x.BasicSalary, TotalIncome = x.TotalIncome, TotalDeduction = x.TotalDeduction, TakeHomePay = x.TakeHomePay }) .ToListAsync(cancellationToken); return data; } }