41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
|
|
|
public class GetEmployeeDeductionByIdResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? DeductionId { get; set; }
|
|
public string? DeductionName { get; set; }
|
|
public decimal Amount { get; set; }
|
|
public string? Description { get; set; }
|
|
public bool IsActive { get; set; }
|
|
}
|
|
|
|
public record GetEmployeeDeductionByIdQuery(string Id) : IRequest<GetEmployeeDeductionByIdResponse>;
|
|
|
|
public class GetEmployeeDeductionByIdHandler : IRequestHandler<GetEmployeeDeductionByIdQuery, GetEmployeeDeductionByIdResponse>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
public GetEmployeeDeductionByIdHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<GetEmployeeDeductionByIdResponse> Handle(GetEmployeeDeductionByIdQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var data = await _context.EmployeeDeduction
|
|
.Where(x => x.Id == request.Id)
|
|
.Select(x => new GetEmployeeDeductionByIdResponse
|
|
{
|
|
Id = x.Id,
|
|
DeductionId = x.DeductionId,
|
|
DeductionName = x.Deduction != null ? x.Deduction.Name : string.Empty,
|
|
Amount = x.Amount,
|
|
Description = x.Description,
|
|
IsActive = x.IsActive
|
|
})
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
|
|
return data!;
|
|
}
|
|
} |