45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
|
|
|
public class LookupEmployeeResponse
|
|
{
|
|
public List<LookupItem> EmployeeGroups { get; set; } = new();
|
|
public List<LookupItem> EmployeeCategories { get; set; } = new();
|
|
}
|
|
|
|
public class LookupItem
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? Name { get; set; }
|
|
}
|
|
|
|
public record LookupEmployeeQuery() : IRequest<LookupEmployeeResponse>;
|
|
|
|
public class LookupEmployeeHandler : IRequestHandler<LookupEmployeeQuery, LookupEmployeeResponse>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public LookupEmployeeHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<LookupEmployeeResponse> Handle(LookupEmployeeQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var result = new LookupEmployeeResponse();
|
|
|
|
result.EmployeeGroups = await _context.EmployeeGroup
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Name)
|
|
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
|
.ToListAsync(cancellationToken);
|
|
|
|
result.EmployeeCategories = await _context.EmployeeCategory
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Name)
|
|
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return result;
|
|
}
|
|
} |