Files
2026-07-21 14:22:06 +07:00

49 lines
1.6 KiB
C#

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<List<GetBranchListResponse>>;
public class GetBranchListHandler : IRequestHandler<GetBranchListQuery, List<GetBranchListResponse>>
{
private readonly AppDbContext _context;
public GetBranchListHandler(AppDbContext context) => _context = context;
public async Task<List<GetBranchListResponse>> 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);
}
}