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