initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Performance.Transfer.Cqrs;
|
||||
|
||||
public class GetTransferByIdResponse : UpdateTransferRequest { }
|
||||
|
||||
public record GetTransferByIdQuery(string Id) : IRequest<GetTransferByIdResponse?>;
|
||||
|
||||
public class GetTransferByIdHandler : IRequestHandler<GetTransferByIdQuery, GetTransferByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetTransferByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetTransferByIdResponse?> Handle(GetTransferByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.Transfer
|
||||
.AsNoTracking()
|
||||
.Include(x => x.Employee)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetTransferByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
EmployeeId = x.EmployeeId,
|
||||
EmployeeName = x.Employee != null ? $"{x.Employee.FirstName} {x.Employee.LastName}" : string.Empty,
|
||||
FromBranchId = x.FromBranchId,
|
||||
FromDepartmentId = x.FromDepartmentId,
|
||||
FromDesignationId = x.FromDesignationId,
|
||||
ToBranchId = x.ToBranchId,
|
||||
ToDepartmentId = x.ToDepartmentId,
|
||||
ToDesignationId = x.ToDesignationId,
|
||||
TransferDate = x.TransferDate,
|
||||
TransferNote = x.TransferNote,
|
||||
Status = x.Status,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user