initial commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Organization.Department.Cqrs;
|
||||
|
||||
public class GetDepartmentListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? CostCenter { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? HeadOfDeptartment { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
public record GetDepartmentListQuery() : IRequest<List<GetDepartmentListResponse>>;
|
||||
|
||||
public class GetDepartmentListHandler : IRequestHandler<GetDepartmentListQuery, List<GetDepartmentListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetDepartmentListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetDepartmentListResponse>> Handle(GetDepartmentListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Department
|
||||
.AsNoTracking()
|
||||
.NotDeletedOnly()
|
||||
.OrderBy(x => x.CostCenter)
|
||||
.Select(x => new GetDepartmentListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
CostCenter = x.CostCenter,
|
||||
Name = x.Name,
|
||||
HeadOfDeptartment = x.HeadOfDeptartment,
|
||||
Description = x.Description,
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user