initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.BookingResource.Cqrs;
|
||||
|
||||
public class LookupBookingGroupResponse
|
||||
{
|
||||
public List<LookupBookingGroupItem> BookingGroups { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupBookingGroupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record LookupBookingGroupQuery() : IRequest<LookupBookingGroupResponse>;
|
||||
|
||||
public class LookupBookingGroupHandler : IRequestHandler<LookupBookingGroupQuery, LookupBookingGroupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public LookupBookingGroupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupBookingGroupResponse> Handle(LookupBookingGroupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var items = await _context.BookingGroup
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupBookingGroupItem
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return new LookupBookingGroupResponse { BookingGroups = items };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user