initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Payroll.Income.Cqrs;
|
||||
|
||||
public class GetIncomeByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Code { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Type { get; set; }
|
||||
public bool IsTaxable { get; set; }
|
||||
public string? CalculationBase { 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 GetIncomeByIdQuery(string Id) : IRequest<GetIncomeByIdResponse?>;
|
||||
|
||||
public class GetIncomeByIdHandler : IRequestHandler<GetIncomeByIdQuery, GetIncomeByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetIncomeByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetIncomeByIdResponse?> Handle(GetIncomeByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Income
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetIncomeByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
Code = x.Code,
|
||||
Name = x.Name,
|
||||
Description = x.Description,
|
||||
Type = x.Type,
|
||||
IsTaxable = x.IsTaxable,
|
||||
CalculationBase = x.CalculationBase,
|
||||
Status = x.Status,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user