Files
blazor-cms/Features/Organization/EmployeeGroup/Cqrs/GetEmployeeGroupListHandler.cs
T
2026-07-21 13:52:43 +07:00

43 lines
1.5 KiB
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Organization.EmployeeGroup.Cqrs;
public class GetEmployeeGroupListResponse
{
public string? Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetEmployeeGroupListQuery() : IRequest<List<GetEmployeeGroupListResponse>>;
public class GetEmployeeGroupListHandler : IRequestHandler<GetEmployeeGroupListQuery, List<GetEmployeeGroupListResponse>>
{
private readonly AppDbContext _context;
public GetEmployeeGroupListHandler(AppDbContext context) => _context = context;
public async Task<List<GetEmployeeGroupListResponse>> Handle(GetEmployeeGroupListQuery request, CancellationToken cancellationToken)
{
return await _context.EmployeeGroup
.AsNoTracking()
.OrderBy(x => x.Name)
.Select(x => new GetEmployeeGroupListResponse
{
Id = x.Id,
Name = x.Name,
Description = x.Description,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy,
})
.ToListAsync(cancellationToken);
}
}