using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; using Indotalent.Data.Enums; namespace Indotalent.Features.Pipeline.Budget.Cqrs; public class BudgetLookupResponse { public List Campaigns { get; set; } = new(); public List Statuses { get; set; } = new(); } public class LookupItem { public string? Id { get; set; } public string? Name { get; set; } public int Value { get; set; } } public record GetBudgetLookupQuery() : IRequest; public class GetBudgetLookupHandler : IRequestHandler { private readonly AppDbContext _context; public GetBudgetLookupHandler(AppDbContext context) => _context = context; public async Task Handle(GetBudgetLookupQuery request, CancellationToken cancellationToken) { var response = new BudgetLookupResponse(); response.Campaigns = await _context.Campaign .AsNoTracking() .OrderBy(x => x.Title) .Select(x => new LookupItem { Id = x.Id, Name = x.Title }) .ToListAsync(cancellationToken); response.Statuses = Enum.GetValues(typeof(BudgetStatus)) .Cast() .Select(x => new LookupItem { Value = (int)x, Name = x.ToString() }) .ToList(); return response; } }