Files
blazor-saas-crm/Features/Pipeline/LeadContact/Cqrs/GetLeadContactListHandler.cs
T
2026-07-21 14:14:44 +07:00

51 lines
1.8 KiB
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Pipeline.LeadContact.Cqrs;
public class GetLeadContactListResponse
{
public string? Id { get; set; }
public string? LeadId { get; set; }
public string? AutoNumber { get; set; }
public string? FullName { get; set; }
public string? MobileNumber { get; set; }
public string? Email { get; set; }
public string? AvatarName { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetLeadContactListQuery() : IRequest<List<GetLeadContactListResponse>>;
public class GetLeadContactListHandler : IRequestHandler<GetLeadContactListQuery, List<GetLeadContactListResponse>>
{
private readonly AppDbContext _context;
public GetLeadContactListHandler(AppDbContext context) => _context = context;
public async Task<List<GetLeadContactListResponse>> Handle(GetLeadContactListQuery request, CancellationToken cancellationToken)
{
return await _context.LeadContact
.AsNoTracking()
.OrderBy(x => x.FullName)
.Select(x => new GetLeadContactListResponse
{
Id = x.Id,
LeadId = x.LeadId,
AutoNumber = x.AutoNumber,
FullName = x.FullName,
MobileNumber = x.MobileNumber,
Email = x.Email,
AvatarName = x.AvatarName,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy
})
.ToListAsync(cancellationToken);
}
}