using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Payroll.Deduction.Cqrs; public class GetDeductionByIdResponse { public string? Id { get; set; } public string? Code { get; set; } public string? Name { get; set; } public string? Description { get; set; } public string? Category { get; set; } public bool PreTax { get; set; } public string? CalculationMethod { 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 GetDeductionByIdQuery(string Id) : IRequest; public class GetDeductionByIdHandler : IRequestHandler { private readonly AppDbContext _context; public GetDeductionByIdHandler(AppDbContext context) => _context = context; public async Task Handle(GetDeductionByIdQuery request, CancellationToken cancellationToken) { return await _context.Deduction .AsNoTracking() .Where(x => x.Id == request.Id) .Select(x => new GetDeductionByIdResponse { Id = x.Id, Code = x.Code, Name = x.Name, Description = x.Description, Category = x.Category, PreTax = x.PreTax, CalculationMethod = x.CalculationMethod, Status = x.Status, CreatedAt = x.CreatedAt, CreatedBy = x.CreatedBy, UpdatedAt = x.UpdatedAt, UpdatedBy = x.UpdatedBy }) .FirstOrDefaultAsync(cancellationToken); } }