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