hrms-api-backend/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs
Suphonchai Phoonsawat 55a0f5c6ed Add Some Report
2023-09-03 20:54:12 +07:00

700 lines
39 KiB
C#

using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Responses.Reports;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories.Commands
{
public class CommandReportRepository : GenericRepository<Guid, Command>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly UserProfileRepository _userProfileRepository;
#endregion
#region " Constructor and Destuctor "
public CommandReportRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor,
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_organizationCommonRepository = organizationCommonRepository;
_userProfileRepository = userProfileRepository;
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
else
return Guid.Empty;
}
}
#endregion
#region " Methods "
public async Task<List<dynamic>> GetCommandType01AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var ret = new List<dynamic>();
foreach (var c in raw_data)
{
ret.Add(new
{
FullName = $"{c.Prefix}{c.FirstName} {c.LastName}",
PositionName = ""
});
}
return ret;
}
catch
{
throw;
}
}
public async Task<List<dynamic>> GetCommandType02AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var ret = new List<dynamic>();
foreach (var c in raw_data)
{
ret.Add(new
{
FullName = $"{c.Prefix}{c.FirstName} {c.LastName}",
PositionName = ""
});
}
return ret;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType03AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType04AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType05_06AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType07AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType08AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementOther>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType09AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementOther>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType15Response>> GetCommandType15AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<PlacementOfficer>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
on r.RefPlacementProfileId equals p.Id
select new CommandType15Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.Organization,
StartDate = p.DateStart == null ? "" : p.DateStart.Value.ToThaiFullDate3(),
EndDate = p.DateEnd == null ? "" : p.DateEnd.Value.ToThaiFullDate3(),
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType17Response>> GetCommandType17AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementResign>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
.Include(p => p.Profile)
.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
select new CommandType17Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld,
PositionLevel = p.PositionLevelOld,
PositionType = p.PositionTypeOld,
PositionNumber = p.PositionNumberOld,
ActiveDate = p.ActiveDate == null ? "" : p.ActiveDate.Value.ToThaiFullDate3(),
Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? 0 : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType18Response>> GetCommandType18Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementOut>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
.Include(p => p.Profile)
.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
select new CommandType18Response
{
CommandNo = r.Command.CommandNo,
CommandYear = r.Command.CommandYear,
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld,
PositionLevel = p.PositionLevelOld,
PositionType = p.PositionTypeOld,
PositionNumber = p.PositionNumberOld,
Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? 0 : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
Fault = r.Command.Fault,
GuiltyBasis = r.Command.GuiltyBasis,
ConclusionFireNo = r.Command!.ConclusionFireNo,
ConclusionFireDate = r.Command.ConclusionFireDate == null ? "" : r.Command.ConclusionFireDate.Value.ToThaiFullDate3(),
ConclusionFireResolution = r.Command.ConclusionFireResolution
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType18Response>> GetCommandType19Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementDischarge>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
.Include(p => p.Profile)
.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
select new CommandType18Response
{
CommandNo = r.Command.CommandNo,
CommandYear = r.Command.CommandYear,
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld,
PositionLevel = p.PositionLevelOld,
PositionType = p.PositionTypeOld,
PositionNumber = p.PositionNumberOld,
Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? 0 : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
Fault = r.Command.Fault,
GuiltyBasis = r.Command.GuiltyBasis,
ConclusionFireNo = r.Command!.ConclusionFireNo,
ConclusionFireDate = r.Command.ConclusionFireDate == null ? "" : r.Command.ConclusionFireDate.Value.ToThaiFullDate3(),
ConclusionFireResolution = r.Command.ConclusionFireResolution
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType18Response>> GetCommandType20Async(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => c.Command.Id == id)
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementExpulsion>()
.Include(p => p.Profile)
.ThenInclude(p => p.Position)
.Include(p => p.Profile)
.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id
select new CommandType18Response
{
CommandNo = r.Command.CommandNo,
CommandYear = r.Command.CommandYear,
CommandAffectDate = r.Command.CommandAffectDate == null ? "" : r.Command.CommandAffectDate.Value.ToThaiFullDate3(),
IssuerOrganizationName = r.Command.IssuerOrganizationName,
AuthorizedUserFullName = r.Command.AuthorizedUserFullName,
AuthorizedPosition = r.Command.AuthorizedPosition,
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name,
Organization = p.OrganizationPositionOld,
PositionLevel = p.PositionLevelOld,
PositionType = p.PositionTypeOld,
PositionNumber = p.PositionNumberOld,
Salary = p.Profile.Salaries == null || p.Profile.Salaries.Count == 0 ? 0 : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
Fault = r.Command.Fault,
GuiltyBasis = r.Command.GuiltyBasis,
ConclusionFireNo = r.Command!.ConclusionFireNo,
ConclusionFireDate = r.Command.ConclusionFireDate == null ? "" : r.Command.ConclusionFireDate.Value.ToThaiFullDate3(),
ConclusionFireResolution = r.Command.ConclusionFireResolution
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
#endregion
}
}