67 lines
2.7 KiB
C#
67 lines
2.7 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Performance.Evaluation.Cqrs;
|
|
|
|
public class GetEvaluationByIdResponse
|
|
{
|
|
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? EvaluatorId { get; set; }
|
|
public string? EvaluatorCode { get; set; }
|
|
public string? EvaluatorName { get; set; }
|
|
public DateTime EvaluationDate { get; set; }
|
|
public string? EvaluationNote { get; set; }
|
|
public string? Status { get; set; }
|
|
public DateTimeOffset? CreatedAt { get; set; }
|
|
public string? CreatedBy { get; set; }
|
|
public DateTimeOffset? UpdatedAt { get; set; }
|
|
public string? UpdatedBy { get; set; }
|
|
}
|
|
|
|
public record GetEvaluationByIdQuery(string Id) : IRequest<GetEvaluationByIdResponse?>;
|
|
|
|
public class GetEvaluationByIdHandler : IRequestHandler<GetEvaluationByIdQuery, GetEvaluationByIdResponse?>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetEvaluationByIdHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<GetEvaluationByIdResponse?> Handle(GetEvaluationByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Evaluation
|
|
.AsNoTracking()
|
|
.Include(x => x.Employee)
|
|
.Include(x => x.Evaluator)
|
|
.Where(x => x.Id == request.Id)
|
|
.Select(x => new GetEvaluationByIdResponse
|
|
{
|
|
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,
|
|
EvaluatorId = x.EvaluatorId,
|
|
EvaluatorCode = x.Evaluator != null ? x.Evaluator.Code : string.Empty,
|
|
EvaluatorName = x.Evaluator != null ? $"{x.Evaluator.FirstName} {x.Evaluator.LastName}" : string.Empty,
|
|
EvaluationDate = x.EvaluationDate,
|
|
EvaluationNote = x.EvaluationNote,
|
|
Status = x.Status,
|
|
CreatedAt = x.CreatedAt,
|
|
CreatedBy = x.CreatedBy,
|
|
UpdatedAt = x.UpdatedAt,
|
|
UpdatedBy = x.UpdatedBy
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
} |