diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs index 71a53a03..385624b1 100644 --- a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs @@ -39,6 +39,8 @@ namespace BMA.EHR.Application.Responses.Profiles public string? Gender { get; set; } + public string ProfileType { get; set; } = string.Empty; + } public class PosLevel @@ -89,9 +91,11 @@ namespace BMA.EHR.Application.Responses.Profiles public string PositionLevel { get; set; } = string.Empty; - public string PositionType { get; set; } = string.Empty; + public string PositionType { get; set; } = string.Empty; public string Position { get; set; } = string.Empty; + + } public class ProfileInsignia diff --git a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs index 31ac70b1..8240ed9b 100644 --- a/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs @@ -1041,10 +1041,13 @@ namespace BMA.EHR.Insignia.Service.Controllers //var profile = await _context.Profiles.Include(x => x.Salaries).FirstOrDefaultAsync(x => x.Id == req.ProfileId); - var profile = _userProfileRepository.GetOfficerProfileById(req.ProfileId, AccessToken); + var profileTest = _userProfileRepository.GetOfficerProfileById(req.ProfileId, AccessToken); - if (profile == null) + if (profileTest == null) return Error(GlobalMessages.DataNotFound); + + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(profileTest.Keycloak ?? Guid.Empty, AccessToken ?? ""); + var insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Id == req.insigniaId); if (insignia == null) @@ -1103,6 +1106,15 @@ namespace BMA.EHR.Insignia.Service.Controllers } + var lastInsignia = string.Empty; + if (profile.ProfileInsignia != null) + { + var id = profile.ProfileInsignia.Id ?? Guid.Empty; + var insigniaEnt = _insigniaPeriodRepository.GetInsigniaById(id); + if (insigniaEnt != null) + lastInsignia = insigniaEnt.Name; + } + await _context.AddAsync(new InsigniaRequestProfile { Status = "PENDING", @@ -1112,8 +1124,7 @@ namespace BMA.EHR.Insignia.Service.Controllers Reason = req.Reason, RequestDate = DateTime.Now, MatchingConditions = System.Text.Json.JsonSerializer.Serialize(new List()), // serialize to string - Salary = profile.ProfileSalary == null || profile.ProfileSalary.Count == 0 ? 0 : - profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().Amount, //profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount, + Salary = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, //profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount, CreatedFullName = FullName ?? "System Administrator", CreatedUserId = UserId ?? "", CreatedAt = DateTime.Now, @@ -1133,13 +1144,10 @@ namespace BMA.EHR.Insignia.Service.Controllers Gender = profile.Gender, PosTypeName = profile.PosType!.PosTypeName, PosLevelName = profile.PosLevel!.PosLevelName, - PosNo = profile.ProfileSalary == null || profile.ProfileSalary.Count == 0 ? "" : - profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().PosNo, - Amount = profile.ProfileSalary == null || profile.ProfileSalary.Count == 0 ? 0 : - profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().Amount, - PositionSalaryAmount = profile.ProfileSalary == null || profile.ProfileSalary.Count == 0 ? 0 : - profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount, - LastInsigniaName = "" + PosNo = profile.ProfileSalary == null ? "" : profile.ProfileSalary.PosNo, + Amount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount, + PositionSalaryAmount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.PositionSalaryAmount, + LastInsigniaName = lastInsignia }); await _context.SaveChangesAsync();