initial commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using Indotalent.ConfigBackEnd.Exceptions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Payroll.PayrollDetails.Cqrs;
|
||||
|
||||
public class GetPayrollDetailByIdRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetPayrollDetailByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? PayrollProcessId { get; set; }
|
||||
public string? EmployeeId { get; set; }
|
||||
public string? EmployeeCode { get; set; }
|
||||
public string? EmployeeName { get; set; }
|
||||
public decimal BasicSalary { get; set; }
|
||||
public decimal TotalIncome { get; set; }
|
||||
public decimal TotalDeduction { get; set; }
|
||||
public decimal TakeHomePay { get; set; }
|
||||
public List<PayrollDetailComponentResponse> Components { get; set; } = new();
|
||||
}
|
||||
|
||||
public class PayrollDetailComponentResponse
|
||||
{
|
||||
public string? ComponentName { get; set; }
|
||||
public string? ComponentType { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record GetPayrollDetailByIdQuery(GetPayrollDetailByIdRequest Data) : IRequest<GetPayrollDetailByIdResponse>;
|
||||
|
||||
public class GetPayrollDetailByIdHandler : IRequestHandler<GetPayrollDetailByIdQuery, GetPayrollDetailByIdResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetPayrollDetailByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetPayrollDetailByIdResponse> Handle(GetPayrollDetailByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.PayrollDetail
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new NotFoundException("Payroll Detail", request.Data.Id ?? string.Empty);
|
||||
}
|
||||
|
||||
var response = new GetPayrollDetailByIdResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
PayrollProcessId = entity.PayrollProcessId,
|
||||
EmployeeId = entity.EmployeeId,
|
||||
EmployeeCode = entity.EmployeeCode,
|
||||
EmployeeName = entity.EmployeeName,
|
||||
BasicSalary = entity.BasicSalary,
|
||||
TotalIncome = entity.TotalIncome,
|
||||
TotalDeduction = entity.TotalDeduction,
|
||||
TakeHomePay = entity.TakeHomePay,
|
||||
Components = entity.Components.Select(c => new PayrollDetailComponentResponse
|
||||
{
|
||||
ComponentName = c.ComponentName,
|
||||
ComponentType = c.ComponentType,
|
||||
Amount = c.Amount,
|
||||
Description = c.Description
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user