Files
2026-07-21 14:22:06 +07:00

71 lines
2.5 KiB
C#

using Indotalent.ConfigBackEnd.Exceptions;
using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Payroll.Payrolls.Cqrs;
public class GetPayrollProcessByIdRequest
{
public string? Id { get; set; }
}
public class GetPayrollProcessByIdResponse
{
public string? Id { get; set; }
public string? AutoNumber { get; set; }
public string? PeriodName { get; set; }
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public int TotalEmployees { get; set; }
public decimal TotalBasicSalary { get; set; }
public decimal TotalIncome { get; set; }
public decimal TotalDeduction { get; set; }
public decimal TotalGross { get; set; }
public decimal TotalTakeHomePay { get; set; }
public string? Status { get; set; }
public string? ProcessedBy { get; set; }
public DateTime ProcessedAt { get; set; }
public string? Description { get; set; }
}
public record GetPayrollProcessByIdQuery(GetPayrollProcessByIdRequest Data) : IRequest<GetPayrollProcessByIdResponse>;
public class GetPayrollProcessByIdHandler : IRequestHandler<GetPayrollProcessByIdQuery, GetPayrollProcessByIdResponse>
{
private readonly AppDbContext _context;
public GetPayrollProcessByIdHandler(AppDbContext context) => _context = context;
public async Task<GetPayrollProcessByIdResponse> Handle(GetPayrollProcessByIdQuery request, CancellationToken cancellationToken)
{
var entity = await _context.PayrollProcess
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null)
{
throw new NotFoundException("Payroll Process", request.Data.Id ?? string.Empty);
}
var response = new GetPayrollProcessByIdResponse
{
Id = entity.Id,
AutoNumber = entity.AutoNumber,
PeriodName = entity.PeriodName,
FromDate = entity.FromDate,
ToDate = entity.ToDate,
TotalEmployees = entity.TotalEmployees,
TotalBasicSalary = entity.TotalBasicSalary,
TotalIncome = entity.TotalIncome,
TotalDeduction = entity.TotalDeduction,
TotalGross = entity.TotalGross,
TotalTakeHomePay = entity.TotalTakeHomePay,
Status = entity.Status,
ProcessedBy = entity.ProcessedBy,
ProcessedAt = entity.ProcessedAt,
Description = entity.Description
};
return response;
}
}