using Indotalent.ConfigBackEnd.Extensions; using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Organization.Branch.Cqrs; public class GetBranchListResponse { public string? Id { get; set; } public string? AutoNumber { get; set; } public string? Code { get; set; } public string? Name { get; set; } public string? City { get; set; } public string? Phone { get; set; } public string? Email { get; set; } public string? StreetAddress { get; set; } public string? Description { get; set; } } public record GetBranchListQuery() : IRequest>; public class GetBranchListHandler : IRequestHandler> { private readonly AppDbContext _context; public GetBranchListHandler(AppDbContext context) => _context = context; public async Task> Handle(GetBranchListQuery request, CancellationToken cancellationToken) { return await _context.Branch .AsNoTracking() .NotDeletedOnly() .OrderBy(x => x.Code) .Select(x => new GetBranchListResponse { Id = x.Id, AutoNumber = x.AutoNumber, Code = x.Code, Name = x.Name, City = x.City, Phone = x.Phone, Email = x.Email, StreetAddress = x.StreetAddress, Description = x.Description, }) .ToListAsync(cancellationToken); } }