47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Payroll.Grade.Cqrs;
|
|
|
|
public class GetGradeListResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? Code { get; set; }
|
|
public string? Name { get; set; }
|
|
public decimal SalaryFrom { get; set; }
|
|
public decimal SalaryTo { get; set; }
|
|
public string? Description { get; set; }
|
|
public bool IsOverTimeEligible { get; set; }
|
|
public string? Status { get; set; }
|
|
public DateTimeOffset? CreatedAt { get; set; }
|
|
}
|
|
|
|
public record GetGradeListQuery() : IRequest<List<GetGradeListResponse>>;
|
|
|
|
public class GetGradeListHandler : IRequestHandler<GetGradeListQuery, List<GetGradeListResponse>>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetGradeListHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<List<GetGradeListResponse>> Handle(GetGradeListQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Grade
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Code)
|
|
.Select(x => new GetGradeListResponse
|
|
{
|
|
Id = x.Id,
|
|
Code = x.Code,
|
|
Name = x.Name,
|
|
SalaryFrom = x.SalaryFrom,
|
|
SalaryTo = x.SalaryTo,
|
|
Description = x.Description,
|
|
IsOverTimeEligible = x.IsOverTimeEligible,
|
|
Status = x.Status,
|
|
CreatedAt = x.CreatedAt
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
} |