using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Organization.Employee.Cqrs; public class GetEmployeeByIdResponse { public string? Id { get; set; } public string? AutoNumber { get; set; } public string? Name { get; set; } public string? Description { get; set; } public string? Street { get; set; } public string? City { get; set; } public string? State { get; set; } public string? ZipCode { get; set; } public string? Country { get; set; } public string? PhoneNumber { get; set; } public string? FaxNumber { get; set; } public string? EmailAddress { get; set; } public string? Website { get; set; } public string? WhatsApp { get; set; } public string? LinkedIn { get; set; } public string? Facebook { get; set; } public string? Instagram { get; set; } public string? TwitterX { get; set; } public string? TikTok { get; set; } public string? EmployeeGroupId { get; set; } public string? EmployeeCategoryId { get; set; } public string? JobTitle { get; set; } public decimal CommissionRate { get; set; } public string? EmployeeNumber { get; set; } public DateTimeOffset? CreatedAt { get; set; } public string? CreatedBy { get; set; } public DateTimeOffset? UpdatedAt { get; set; } public string? UpdatedBy { get; set; } } public record GetEmployeeByIdQuery(string Id) : IRequest; public class GetEmployeeByIdHandler : IRequestHandler { private readonly AppDbContext _context; public GetEmployeeByIdHandler(AppDbContext context) => _context = context; public async Task Handle(GetEmployeeByIdQuery request, CancellationToken cancellationToken) { return await _context.Employee .AsNoTracking() .Where(x => x.Id == request.Id) .Select(x => new GetEmployeeByIdResponse { Id = x.Id, AutoNumber = x.AutoNumber, Name = x.Name, Description = x.Description, Street = x.Street, City = x.City, State = x.State, ZipCode = x.ZipCode, Country = x.Country, PhoneNumber = x.PhoneNumber, FaxNumber = x.FaxNumber, EmailAddress = x.EmailAddress, Website = x.Website, WhatsApp = x.WhatsApp, LinkedIn = x.LinkedIn, Facebook = x.Facebook, Instagram = x.Instagram, TwitterX = x.TwitterX, TikTok = x.TikTok, EmployeeGroupId = x.EmployeeGroupId, EmployeeCategoryId = x.EmployeeCategoryId, JobTitle = x.JobTitle, CommissionRate = x.CommissionRate, EmployeeNumber = x.EmployeeNumber, CreatedAt = x.CreatedAt, CreatedBy = x.CreatedBy, UpdatedAt = x.UpdatedAt, UpdatedBy = x.UpdatedBy }) .FirstOrDefaultAsync(cancellationToken); } }