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

55 lines
2.1 KiB
C#

using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
public class GetEvaluationListResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? EmployeeId { get; set; }
public string? EmployeeCode { get; set; }
public string? EmployeeName { get; set; }
public string? Period { get; set; }
public string? FinalScore { get; set; }
public string? Rating { get; set; }
public string? EvaluatorName { get; set; }
public string? Status { get; set; }
public DateTime EvaluationDate { get; set; }
}
public record GetEvaluationListQuery() : IRequest<List<GetEvaluationListResponse>>;
public class GetEvaluationListHandler : IRequestHandler<GetEvaluationListQuery, List<GetEvaluationListResponse>>
{
private readonly AppDbContext _context;
public GetEvaluationListHandler(AppDbContext context) => _context = context;
public async Task<List<GetEvaluationListResponse>> Handle(GetEvaluationListQuery request, CancellationToken cancellationToken)
{
return await _context.Evaluation
.AsNoTracking()
.NotDeletedOnly()
.Include(x => x.Employee)
.Include(x => x.Evaluator)
.OrderByDescending(x => x.EvaluationDate)
.Select(x => new GetEvaluationListResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
EmployeeId = x.EmployeeId,
EmployeeCode = x.Employee != null ? x.Employee.Code : string.Empty,
EmployeeName = x.Employee != null ? $"{x.Employee.FirstName} {x.Employee.LastName}" : string.Empty,
Period = x.Period,
FinalScore = x.FinalScore,
Rating = x.Rating,
EvaluatorName = x.Evaluator != null ? $"{x.Evaluator.FirstName} {x.Evaluator.LastName}" : string.Empty,
Status = x.Status,
EvaluationDate = x.EvaluationDate
})
.ToListAsync(cancellationToken);
}
}