Files
2026-07-21 14:08:10 +07:00

45 lines
1.5 KiB
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Deduction.Cqrs;
public class GetDeductionListResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
public string? Name { get; set; }
public string? Category { get; set; }
public bool PreTax { get; set; }
public string? CalculationMethod { get; set; }
public string? Status { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
}
public record GetDeductionListQuery() : IRequest<List<GetDeductionListResponse>>;
public class GetDeductionListHandler : IRequestHandler<GetDeductionListQuery, List<GetDeductionListResponse>>
{
private readonly AppDbContext _context;
public GetDeductionListHandler(AppDbContext context) => _context = context;
public async Task<List<GetDeductionListResponse>> Handle(GetDeductionListQuery request, CancellationToken cancellationToken)
{
return await _context.Deduction
.AsNoTracking()
.OrderBy(x => x.Code)
.Select(x => new GetDeductionListResponse
{
Id = x.Id,
Code = x.Code,
Name = x.Name,
Category = x.Category,
PreTax = x.PreTax,
CalculationMethod = x.CalculationMethod,
Status = x.Status,
CreatedAt = x.CreatedAt
})
.ToListAsync(cancellationToken);
}
}