Files
blazor-hrm/Features/Leave/LeaveRequest/Cqrs/GetEmployeeLeaveReference.cs
T
2026-07-21 14:08:10 +07:00

35 lines
1.2 KiB
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Leave.LeaveRequest.Cqrs;
public class EmployeeLeaveReferenceResponse
{
public string? Id { get; set; }
public string? Code { get; set; }
public string? FullName { get; set; }
}
public record GetEmployeeLeaveReferenceQuery() : IRequest<List<EmployeeLeaveReferenceResponse>>;
public class GetEmployeeLeaveReferenceHandler : IRequestHandler<GetEmployeeLeaveReferenceQuery, List<EmployeeLeaveReferenceResponse>>
{
private readonly AppDbContext _context;
public GetEmployeeLeaveReferenceHandler(AppDbContext context) => _context = context;
public async Task<List<EmployeeLeaveReferenceResponse>> Handle(GetEmployeeLeaveReferenceQuery request, CancellationToken cancellationToken)
{
return await _context.Employee
.AsNoTracking()
.Where(x => x.EmployeeStatus == "Active")
.Select(x => new EmployeeLeaveReferenceResponse
{
Id = x.Id,
Code = x.Code,
FullName = $"{x.FirstName} {x.LastName}"
})
.ToListAsync(cancellationToken);
}
}