35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Utilities.ProgramResource.Cqrs;
|
|
|
|
public class GetProgramResourceListResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? Name { get; set; }
|
|
public string? Description { get; set; }
|
|
}
|
|
|
|
public record GetProgramResourceListQuery() : IRequest<List<GetProgramResourceListResponse>>;
|
|
|
|
public class GetProgramResourceListHandler : IRequestHandler<GetProgramResourceListQuery, List<GetProgramResourceListResponse>>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetProgramResourceListHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<List<GetProgramResourceListResponse>> Handle(GetProgramResourceListQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.ProgramManagerResource
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Name)
|
|
.Select(x => new GetProgramResourceListResponse
|
|
{
|
|
Id = x.Id,
|
|
Name = x.Name,
|
|
Description = x.Description
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
} |