using Indotalent.ConfigBackEnd.Extensions; using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Performance.Transfer.Cqrs; public class LookupResponse { public string Id { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; } public record GetBranchLookupQuery() : IRequest>; public record GetDepartmentLookupQuery() : IRequest>; public record GetDesignationLookupQuery() : IRequest>; public class GetTransferLookupsHandler : IRequestHandler>, IRequestHandler>, IRequestHandler> { private readonly AppDbContext _context; public GetTransferLookupsHandler(AppDbContext context) => _context = context; public async Task> Handle(GetBranchLookupQuery request, CancellationToken ct) { return await _context.Branch.AsNoTracking().NotDeletedOnly() .Select(x => new LookupResponse { Id = x.Id, Name = x.Name ?? "" }).ToListAsync(ct); } public async Task> Handle(GetDepartmentLookupQuery request, CancellationToken ct) { return await _context.Department.AsNoTracking().NotDeletedOnly() .Select(x => new LookupResponse { Id = x.Id, Name = x.Name ?? "" }).ToListAsync(ct); } public async Task> Handle(GetDesignationLookupQuery request, CancellationToken ct) { return await _context.Designation.AsNoTracking().NotDeletedOnly() .Select(x => new LookupResponse { Id = x.Id, Name = x.Name ?? "" }).ToListAsync(ct); } }