initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Employee.Cqrs;
|
||||
|
||||
public class GetEmployeeListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? EmailAddress { get; set; }
|
||||
public string? EmployeeGroupName { get; set; }
|
||||
public string? EmployeeCategoryName { get; set; }
|
||||
}
|
||||
|
||||
public record GetEmployeeListQuery() : IRequest<List<GetEmployeeListResponse>>;
|
||||
|
||||
public class GetEmployeeListHandler : IRequestHandler<GetEmployeeListQuery, List<GetEmployeeListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetEmployeeListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetEmployeeListResponse>> Handle(GetEmployeeListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Employee
|
||||
.AsNoTracking()
|
||||
.Include(x => x.EmployeeGroup)
|
||||
.Include(x => x.EmployeeCategory)
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new GetEmployeeListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Name = x.Name,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
EmailAddress = x.EmailAddress,
|
||||
EmployeeGroupName = x.EmployeeGroup != null ? x.EmployeeGroup.Name : string.Empty,
|
||||
EmployeeCategoryName = x.EmployeeCategory != null ? x.EmployeeCategory.Name : string.Empty
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user