using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Organization.Employee.Cqrs; public class GetEmployeeIncomeListResponse { public string? Id { get; set; } public string? IncomeId { get; set; } public string? EmployeeCode { get; set; } public string? IncomeName { get; set; } public string? IncomeType { get; set; } public decimal Amount { get; set; } public string? Description { get; set; } public bool IsActive { get; set; } } public record GetEmployeeIncomeListByEmployeeIdQuery(string EmployeeId) : IRequest>; public class GetEmployeeIncomeListByEmployeeIdHandler : IRequestHandler> { private readonly AppDbContext _context; public GetEmployeeIncomeListByEmployeeIdHandler(AppDbContext context) => _context = context; public async Task> Handle(GetEmployeeIncomeListByEmployeeIdQuery request, CancellationToken cancellationToken) { var data = await _context.EmployeeIncome .Where(x => x.EmployeeId == request.EmployeeId) .Select(x => new GetEmployeeIncomeListResponse { Id = x.Id, IncomeId = x.IncomeId, EmployeeCode = x.Employee != null ? x.Employee.Code : string.Empty, IncomeName = x.Income != null ? x.Income.Name : string.Empty, IncomeType = x.Income != null ? x.Income.Type : string.Empty, Amount = x.Amount, Description = x.Description, IsActive = x.IsActive }) .OrderBy(x => x.IncomeName) .ToListAsync(cancellationToken); return data; } }