64 lines
2.5 KiB
C#
64 lines
2.5 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Performance.Appraisal.Cqrs;
|
|
|
|
public class GetAppraisalByIdResponse
|
|
{
|
|
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? LastRating { get; set; }
|
|
public decimal CurrentSalary { get; set; }
|
|
public decimal IncrementPercentage { get; set; }
|
|
public decimal NewSalary { get; set; }
|
|
public string? AppraisalType { get; set; }
|
|
public DateTime EffectiveDate { get; set; }
|
|
public string? AppraisalNote { 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 GetAppraisalByIdQuery(string Id) : IRequest<GetAppraisalByIdResponse?>;
|
|
|
|
public class GetAppraisalByIdHandler : IRequestHandler<GetAppraisalByIdQuery, GetAppraisalByIdResponse?>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetAppraisalByIdHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<GetAppraisalByIdResponse?> Handle(GetAppraisalByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Appraisal
|
|
.AsNoTracking()
|
|
.Include(x => x.Employee)
|
|
.Where(x => x.Id == request.Id)
|
|
.Select(x => new GetAppraisalByIdResponse
|
|
{
|
|
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,
|
|
LastRating = x.LastRating,
|
|
CurrentSalary = x.CurrentSalary,
|
|
IncrementPercentage = x.IncrementPercentage,
|
|
NewSalary = x.NewSalary,
|
|
AppraisalType = x.AppraisalType,
|
|
EffectiveDate = x.EffectiveDate,
|
|
AppraisalNote = x.AppraisalNote,
|
|
Status = x.Status,
|
|
CreatedAt = x.CreatedAt,
|
|
CreatedBy = x.CreatedBy,
|
|
UpdatedAt = x.UpdatedAt,
|
|
UpdatedBy = x.UpdatedBy
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
} |