56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using Indotalent.ConfigBackEnd.Extensions;
|
|
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Performance.Transfer.Cqrs;
|
|
|
|
public class GetTransferListResponse
|
|
{
|
|
public string? Id { get; set; }
|
|
public string? AutoNumber { get; set; }
|
|
public string? EmployeeId { get; set; }
|
|
public string? EmployeeName { get; set; }
|
|
public string? FromDept { get; set; }
|
|
public string? FromLocation { get; set; }
|
|
public string? ToDept { get; set; }
|
|
public string? ToLocation { get; set; }
|
|
public DateTime? TransferDate { get; set; }
|
|
public string? Status { get; set; }
|
|
}
|
|
|
|
public record GetTransferListQuery() : IRequest<List<GetTransferListResponse>>;
|
|
|
|
public class GetTransferListHandler : IRequestHandler<GetTransferListQuery, List<GetTransferListResponse>>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public GetTransferListHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<List<GetTransferListResponse>> Handle(GetTransferListQuery request, CancellationToken cancellationToken)
|
|
{
|
|
return await _context.Transfer
|
|
.AsNoTracking()
|
|
.NotDeletedOnly()
|
|
.Include(x => x.Employee)
|
|
.Include(x => x.FromDepartment)
|
|
.Include(x => x.ToDepartment)
|
|
.Include(x => x.FromBranch)
|
|
.Include(x => x.ToBranch)
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(x => new GetTransferListResponse
|
|
{
|
|
Id = x.Id,
|
|
AutoNumber = x.AutoNumber,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeName = x.Employee != null ? $"{x.Employee.FirstName} {x.Employee.LastName}" : string.Empty,
|
|
FromDept = x.FromDepartment != null ? x.FromDepartment.Name : string.Empty,
|
|
FromLocation = x.FromBranch != null ? x.FromBranch.Name : string.Empty,
|
|
ToDept = x.ToDepartment != null ? x.ToDepartment.Name : string.Empty,
|
|
ToLocation = x.ToBranch != null ? x.ToBranch.Name : string.Empty,
|
|
TransferDate = x.TransferDate,
|
|
Status = x.Status
|
|
})
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
} |