using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Pipeline.LeadContact.Cqrs; public class GetLeadContactByIdResponse { public string? Id { get; set; } public string? LeadId { get; set; } public string? AutoNumber { get; set; } public string? FullName { get; set; } public string? Description { get; set; } public string? AddressStreet { get; set; } public string? AddressCity { get; set; } public string? AddressState { get; set; } public string? AddressZipCode { get; set; } public string? AddressCountry { get; set; } public string? PhoneNumber { get; set; } public string? FaxNumber { get; set; } public string? MobileNumber { get; set; } public string? Email { get; set; } public string? Website { get; set; } public string? WhatsApp { get; set; } public string? LinkedIn { get; set; } public string? Facebook { get; set; } public string? Twitter { get; set; } public string? Instagram { 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 GetLeadContactByIdQuery(string Id) : IRequest; public class GetLeadContactByIdHandler : IRequestHandler { private readonly AppDbContext _context; public GetLeadContactByIdHandler(AppDbContext context) => _context = context; public async Task Handle(GetLeadContactByIdQuery request, CancellationToken cancellationToken) { return await _context.LeadContact .AsNoTracking() .Where(x => x.Id == request.Id) .Select(x => new GetLeadContactByIdResponse { Id = x.Id, LeadId = x.LeadId, AutoNumber = x.AutoNumber, FullName = x.FullName, Description = x.Description, AddressStreet = x.AddressStreet, AddressCity = x.AddressCity, AddressState = x.AddressState, AddressZipCode = x.AddressZipCode, AddressCountry = x.AddressCountry, PhoneNumber = x.PhoneNumber, FaxNumber = x.FaxNumber, MobileNumber = x.MobileNumber, Email = x.Email, Website = x.Website, WhatsApp = x.WhatsApp, LinkedIn = x.LinkedIn, Facebook = x.Facebook, Twitter = x.Twitter, Instagram = x.Instagram, AvatarName = x.AvatarName, CreatedAt = x.CreatedAt, CreatedBy = x.CreatedBy, UpdatedAt = x.UpdatedAt, UpdatedBy = x.UpdatedBy }) .FirstOrDefaultAsync(cancellationToken); } }