initial commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
||||
|
||||
public class GetEmployeeIncomeByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? IncomeId { get; set; }
|
||||
public string? IncomeName { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
|
||||
public record GetEmployeeIncomeByIdQuery(string Id) : IRequest<GetEmployeeIncomeByIdResponse>;
|
||||
|
||||
public class GetEmployeeIncomeByIdHandler : IRequestHandler<GetEmployeeIncomeByIdQuery, GetEmployeeIncomeByIdResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public GetEmployeeIncomeByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetEmployeeIncomeByIdResponse> Handle(GetEmployeeIncomeByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var data = await _context.EmployeeIncome
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetEmployeeIncomeByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
IncomeId = x.IncomeId,
|
||||
IncomeName = x.Income != null ? x.Income.Name : string.Empty,
|
||||
Amount = x.Amount,
|
||||
Description = x.Description,
|
||||
IsActive = x.IsActive
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return data!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user