50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using Indotalent.ConfigBackEnd.Extensions;
|
|
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Performance.Promotion.Cqrs;
|
|
|
|
public class GetPromotionListResponse
|
|
{
|
|
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? FromGrade { get; set; }
|
|
public string? ToGrade { get; set; }
|
|
public DateTime? EffectiveDate { get; set; }
|
|
public string? Status { get; set; }
|
|
}
|
|
|
|
public record GetPromotionListQuery() : IRequest<List<GetPromotionListResponse>>;
|
|
|
|
public class GetPromotionListHandler : IRequestHandler<GetPromotionListQuery, List<GetPromotionListResponse>>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetPromotionListHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<List<GetPromotionListResponse>> Handle(GetPromotionListQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Promotion
|
|
.AsNoTracking()
|
|
.NotDeletedOnly()
|
|
.Include(x => x.Employee)
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(x => new GetPromotionListResponse
|
|
{
|
|
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,
|
|
FromGrade = x.FromGrade,
|
|
ToGrade = x.ToGrade,
|
|
EffectiveDate = x.EffectiveDate,
|
|
Status = x.Status
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
} |