diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index a520f502..ddee97cb 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -297,10 +297,10 @@ namespace BMA.EHR.Application.Repositories : p.ProfileInsignia!.OrderByDescending(x => x.Year).FirstOrDefault()!.InsigniaId.Value, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PositionSalaryAmount = p.PositionSalaryAmount ?? 0, ProfileInsignia = p.ProfileInsignia, @@ -409,7 +409,7 @@ namespace BMA.EHR.Application.Repositories var s2_a = (from p in allProfilesByRoot where p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + && (p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id && x.InsigniaId.Value == bcpRoyal.Id) .ToList() .Count() == 0) @@ -459,22 +459,22 @@ namespace BMA.EHR.Application.Repositories : p.ProfileInsignia!.OrderByDescending(x => x.Year).FirstOrDefault()!.InsigniaId.Value, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, IsHigherLevel = IsHigherLevel(p.ProfileInsignia.ToList() - .Where(x => x.InsigniaId.Value != coinInsignia.Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "เบญจมาภรณ์ช้างเผือก"), FirstRecvInsigniaYear = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) .FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) - .FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) + .FirstOrDefault()?.Year, ProfileType = p.ProfileType, MarkDiscipline = p.MarkDiscipline, @@ -555,7 +555,7 @@ namespace BMA.EHR.Application.Repositories var s3 = (from p in allProfilesByRoot where p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + && (p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id && x.InsigniaId.Value == jtmRoyal.Id) .ToList() .Count() == 0) @@ -590,21 +590,21 @@ namespace BMA.EHR.Application.Repositories : p.ProfileInsignia!.OrderByDescending(x => x.Year).FirstOrDefault()!.InsigniaId.Value, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, IsHigherLevel = IsHigherLevel(p.ProfileInsignia.ToList() - .Where(x => x.InsigniaId.Value != coinInsignia.Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "จัตุรถาภรณ์มงกุฎไทย"), FirstRecvInsigniaYear = p.ProfileInsignia == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) .FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) - .FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == bcmRoyal.Id).OrderBy(x => x.Year) + .FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount ?? 0, Amount = p.Amount ?? 0, RootId = p.RootId, @@ -811,10 +811,10 @@ namespace BMA.EHR.Application.Repositories : p.ProfileInsignia!.OrderByDescending(x => x.Year).FirstOrDefault()!.InsigniaId.Value, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PositionSalaryAmount = p.PositionSalaryAmount ?? 0, ProfileInsignia = p.ProfileInsignia, @@ -923,7 +923,7 @@ namespace BMA.EHR.Application.Repositories var s2 = (from p in allProfilesByRoot where p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + && (p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id && x.InsigniaId.Value == jtmRoyal.Id) .ToList() .Count() == 0) @@ -956,21 +956,21 @@ namespace BMA.EHR.Application.Repositories : p.ProfileInsignia!.OrderByDescending(x => x.Year).FirstOrDefault()!.InsigniaId.Value, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, IsHigherLevel = IsHigherLevel(p.ProfileInsignia.ToList() - .Where(x => x.InsigniaId.Value != coinInsignia.Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "จัตุรถาภรณ์มงกุฎไทย"), FirstRecvInsigniaYear = p.ProfileInsignia == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == bcpRoyal.Id).OrderBy(x => x.Year) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == bcpRoyal.Id).OrderBy(x => x.Year) .FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == bcpRoyal.Id).OrderBy(x => x.Year) - .FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == bcpRoyal.Id).OrderBy(x => x.Year) + .FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount ?? 0, Amount = p.Amount ?? 0, RootId = p.RootId, @@ -1065,7 +1065,7 @@ namespace BMA.EHR.Application.Repositories var s3 = (from p in allProfilesByRoot where p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 - && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + && (p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id && x.InsigniaId.Value == jtcRoyal.Id) .ToList() .Count() == 0) @@ -1098,21 +1098,21 @@ namespace BMA.EHR.Application.Repositories : p.ProfileInsignia!.OrderByDescending(x => x.Year).FirstOrDefault()!.InsigniaId.Value, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, IsHigherLevel = IsHigherLevel(p.ProfileInsignia.ToList() - .Where(x => x.InsigniaId.Value != coinInsignia.Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != coinInsignia.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "จัตุรถาภรณ์ช้างเผือก"), FirstRecvInsigniaYear = p.ProfileInsignia == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == jtmRoyal.Id).OrderBy(x => x.Year) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == jtmRoyal.Id).OrderBy(x => x.Year) .FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == jtmRoyal.Id).OrderBy(x => x.Year) - .FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == jtmRoyal.Id).OrderBy(x => x.Year) + .FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -1311,24 +1311,24 @@ namespace BMA.EHR.Application.Repositories Gender = p.Gender ?? "", LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, ProfileInsignia = p.ProfileInsignia, PositionSalaryAmount = p.PositionSalaryAmount, @@ -1426,8 +1426,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("เบญจมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("เบญจมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -1446,24 +1447,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo ?? "", Gender = p.Gender == null ? "" : p.Gender, @@ -1472,7 +1473,7 @@ namespace BMA.EHR.Application.Repositories PositionTypeId = p.PosTypeId, PositionTypeName = p.PosType, IsHigherLevel = IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "เบญจมาภรณ์ช้างเผือก"), @@ -1573,8 +1574,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("จัตุรถาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("จัตุรถาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -1593,24 +1595,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo ?? "", Gender = p.Gender == null ? "" : p.Gender, @@ -1620,12 +1622,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "จัตุรถาภรณ์มงกุฎไทย"), @@ -1719,8 +1721,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("จัตุรถาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("จัตุรถาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -1739,24 +1742,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo ?? "", Gender = p.Gender == null ? "" : p.Gender, @@ -1766,12 +1769,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "จัตุรถาภรณ์ช้างเผือก"), @@ -1972,8 +1975,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -1992,24 +1996,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -2019,12 +2023,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ตริตาภรณ์มงกุฎไทย"), @@ -2118,8 +2122,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -2138,24 +2143,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -2165,12 +2170,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ตริตาภรณ์ช้างเผือก"), @@ -2180,7 +2185,7 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญงาน").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญงาน").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -2336,8 +2341,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -2356,24 +2362,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -2383,12 +2389,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์มงกุฎไทย"), @@ -2398,7 +2404,7 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -2487,8 +2493,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -2507,24 +2514,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -2534,12 +2541,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์ช้างเผือก"), @@ -2549,7 +2556,7 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -2706,8 +2713,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -2726,24 +2734,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -2753,12 +2761,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์ช้างเผือก"), @@ -2768,7 +2776,7 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -2858,8 +2866,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -2878,24 +2887,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -2905,12 +2914,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์มงกุฎไทย"), @@ -2920,14 +2929,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -3019,8 +3028,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -3039,24 +3049,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -3066,12 +3076,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -3081,14 +3091,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -3265,8 +3275,9 @@ namespace BMA.EHR.Application.Repositories where p.PosType == "วิชาการ" && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -3285,24 +3296,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -3312,12 +3323,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ตริตาภรณ์มงกุฎไทย"), @@ -3327,14 +3338,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -3470,8 +3481,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ตริตาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -3490,24 +3502,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -3517,12 +3529,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ตริตาภรณ์ช้างเผือก"), @@ -3532,14 +3544,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -3628,8 +3640,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -3648,24 +3661,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -3675,12 +3688,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์มงกุฎไทย"), @@ -3690,14 +3703,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -3789,8 +3802,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -3809,24 +3823,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year - 5, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year - 5, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year - 5, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year - 5, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -3836,12 +3850,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์ช้างเผือก"), @@ -3851,14 +3865,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -4034,8 +4048,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -4054,24 +4069,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -4081,12 +4096,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์ช้างเผือก"), @@ -4096,14 +4111,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการพิเศษ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการพิเศษ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -4175,8 +4190,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -4195,24 +4211,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -4222,12 +4238,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์มงกุฎไทย"), @@ -4238,14 +4254,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการพิเศษ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ชำนาญการพิเศษ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -4409,8 +4425,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -4429,24 +4446,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -4456,12 +4473,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์ช้างเผือก"), @@ -4471,14 +4488,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "เชี่ยวชาญ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "เชี่ยวชาญ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -4568,8 +4585,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -4588,24 +4606,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -4615,12 +4633,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์มงกุฎไทย"), @@ -4631,14 +4649,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "เชี่ยวชาญ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "เชี่ยวชาญ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -4729,8 +4747,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -4749,24 +4768,24 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -4776,12 +4795,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -4791,14 +4810,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "เชี่ยวชาญ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "เชี่ยวชาญ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -4972,8 +4991,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -4992,25 +5012,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -5020,12 +5040,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -5035,14 +5055,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -5139,8 +5159,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .ToList() .Count() == 0) select new @@ -5159,25 +5180,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo == null ? "" : p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -5187,12 +5208,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาวชิรมงกุฎ"), @@ -5202,14 +5223,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -5306,8 +5327,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -5326,25 +5348,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, @@ -5355,12 +5377,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาปรมาภรณ์ช้างเผือก"), @@ -5371,12 +5393,12 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -5555,8 +5577,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -5575,25 +5598,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -5603,12 +5626,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -5618,14 +5641,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -5722,8 +5745,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .ToList() .Count() == 0) select new @@ -5742,25 +5766,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -5770,12 +5794,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาวชิรมงกุฎ"), @@ -5785,14 +5809,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "อาวุโส").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -5889,8 +5913,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -5909,25 +5934,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -5937,12 +5962,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาปรมาภรณ์ช้างเผือก"), @@ -5952,12 +5977,12 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) .FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ทรงคุณวุฒิ").OrderBy(p => p.Date) - .FirstOrDefault().Date, + .FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -6134,8 +6159,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -6154,25 +6180,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo == null ? "" : p.PosNo, Gender = p.Gender == null ? "" : p.Gender, @@ -6182,12 +6208,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ทวีติยาภรณ์ช้างเผือก"), @@ -6197,12 +6223,12 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "อำนวยการ") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "อำนวยการ") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -6291,8 +6317,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -6311,25 +6338,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? "" : p.Gender, @@ -6339,12 +6366,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์มงกุฎไทย"), @@ -6354,14 +6381,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "อำนวยการ") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "อำนวยการ") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -6519,8 +6546,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -6539,25 +6567,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? "" : p.Gender, @@ -6567,12 +6595,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์มงกุฎไทย"), @@ -6582,14 +6610,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "อำนวยการ") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "อำนวยการ") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -6680,8 +6708,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -6700,25 +6729,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? "" : p.Gender, @@ -6728,12 +6757,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -6743,14 +6772,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "อำนวยการ") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "อำนวยการ") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -6842,8 +6871,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .ToList() .Count() == 0) select new @@ -6862,25 +6892,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? "" : p.Gender, @@ -6890,12 +6920,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาวชิรมงกุฎ"), @@ -6905,14 +6935,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "อำนวยการ") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "อำนวยการ") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -7083,8 +7113,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .ToList() .Count() == 0) select new @@ -7103,25 +7134,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -7131,12 +7162,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์มงกุฎไทย"), @@ -7146,14 +7177,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "บริหาร") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "บริหาร") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ทวีติยาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -7244,8 +7275,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -7264,25 +7296,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -7292,12 +7324,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -7307,14 +7339,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "บริหาร") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "บริหาร") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -7405,8 +7437,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .ToList() .Count() == 0) select new @@ -7425,25 +7458,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -7453,12 +7486,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาวชิรมงกุฎ"), @@ -7468,14 +7501,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "บริหาร") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "ต้น" && x.PositionType == "บริหาร") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -7617,8 +7650,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -7637,25 +7671,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -7665,12 +7699,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "ประถมาภรณ์ช้างเผือก"), @@ -7680,14 +7714,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "บริหาร") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "บริหาร") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์มงกุฎไทย")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -7784,8 +7818,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .ToList() .Count() == 0) select new @@ -7804,25 +7839,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -7832,12 +7867,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาวชิรมงกุฎ"), @@ -7847,14 +7882,14 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "บริหาร") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "บริหาร") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : p.ProfileInsignia - .Where(x => x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("ประถมาภรณ์ช้างเผือก")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -7951,8 +7986,9 @@ namespace BMA.EHR.Application.Repositories && p.ProfileInsignia != null && p.ProfileInsignia.Count > 0 && (p.ProfileInsignia.Where(x => - x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก").Id) + x.InsigniaId.HasValue && + x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id && + x.InsigniaId.Value == GetInsigniaByName("มหาปรมาภรณ์ช้างเผือก")?.Id) .ToList() .Count() == 0) select new @@ -7971,25 +8007,25 @@ namespace BMA.EHR.Application.Repositories ProfileDateAppoint = p.DateAppoint.Value, LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryPosition = p.PositionSalaryAmount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PosNo = p.PosNo, Gender = p.Gender == null ? null : p.Gender, @@ -7999,12 +8035,12 @@ namespace BMA.EHR.Application.Repositories PositionTypeName = p.PosType, IsHigherLevel = p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? true : IsHigherLevel(p.ProfileInsignia - .Where(x => x.InsigniaId.Value != - GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != + GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .OrderByDescending(x => x.Year) .FirstOrDefault(), "มหาปรมาภรณ์ช้างเผือก"), @@ -8014,12 +8050,12 @@ namespace BMA.EHR.Application.Repositories p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "บริหาร") .OrderBy(p => p.Date).FirstOrDefault() == null ? null : p.ProfileSalary.Where(x => x.PositionLevel == "สูง" && x.PositionType == "บริหาร") - .OrderBy(p => p.Date).FirstOrDefault().Date, + .OrderBy(p => p.Date).FirstOrDefault()?.Date, FirstRecvInsigniaYear = p.ProfileInsignia.Count == 0 ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) .OrderBy(x => x.Year).FirstOrDefault() == null ? 0 : - p.ProfileInsignia.Where(x => x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ").Id) - .OrderBy(x => x.Year).FirstOrDefault().Year, + p.ProfileInsignia.Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value == GetInsigniaByName("มหาวชิรมงกุฎ")?.Id) + .OrderBy(x => x.Year).FirstOrDefault()?.Year, PositionSalaryAmount = p.PositionSalaryAmount, Amount = p.Amount, RootId = p.RootId, @@ -8179,144 +8215,146 @@ namespace BMA.EHR.Application.Repositories if (type.ToLower().Trim() == "officer") { var allOfficerProfilesByRoot = (await _userProfileRepository.GetOfficerProfileByRootIdAsync(ocId, AccessToken)); - - // calculate ตามแต่ละชั้น - var type_coin = allOfficerProfilesByRoot.Count() > 0 ? await GetCoinCandidate(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type1_level1 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level1(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type1_level2 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level2(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type1_level3 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level3(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type1_level4 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level4(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type2_level5 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level5(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type2_level6 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level6(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type2_level7 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level7(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type2_level8 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level8(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type2_level9_1 = - allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level9_1(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type2_level9_2 = - allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level9_2(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type3_level10 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type3_Level10(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type3_level11 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type3_Level11(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type4_level10 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type4_Level10(periodId, ocId, allOfficerProfilesByRoot) : new List(); - var type4_level11 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type4_Level11(periodId, ocId, allOfficerProfilesByRoot) : new List(); - - - // union result - foreach (var r in type_coin) + if (allOfficerProfilesByRoot != null) { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type4_level11) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type4_level10) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type3_level11) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type3_level10) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type2_level9_2) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type2_level9_1) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type2_level8) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type2_level7) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type2_level6) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type2_level5) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type1_level4) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type1_level3) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type1_level2) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - foreach (var r in type1_level1) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } - - // ย้ายที่ตามที่ มอสแจ้ง - if (period.Round != 1) - { - var insigniaIdList = await _dbContext.Set() - .Include(x => x.InsigniaType) - .Where(x => x.InsigniaType!.Name == "ชั้นสายสะพาย") - .Select(x => x.Id) - .ToListAsync(); + // calculate ตามแต่ละชั้น + var type_coin = allOfficerProfilesByRoot.Count() > 0 ? await GetCoinCandidate(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type1_level1 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level1(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type1_level2 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level2(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type1_level3 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level3(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type1_level4 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type1_Level4(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type2_level5 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level5(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type2_level6 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level6(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type2_level7 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level7(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type2_level8 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level8(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type2_level9_1 = + allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level9_1(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type2_level9_2 = + allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type2_Level9_2(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type3_level10 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type3_Level10(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type3_level11 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type3_Level11(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type4_level10 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type4_Level10(periodId, ocId, allOfficerProfilesByRoot) : new List(); + var type4_level11 = allOfficerProfilesByRoot.Count() > 0 ? await GetInsigniaCandidate_Type4_Level11(periodId, ocId, allOfficerProfilesByRoot) : new List(); - result_candidate = result_candidate.Where(x => insigniaIdList.Contains(x.RequestInsignia.Id)).ToList(); + // union result + foreach (var r in type_coin) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type4_level11) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type4_level10) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type3_level11) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type3_level10) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type2_level9_2) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type2_level9_1) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type2_level8) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type2_level7) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type2_level6) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type2_level5) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type1_level4) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type1_level3) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type1_level2) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in type1_level1) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + // ย้ายที่ตามที่ มอสแจ้ง + if (period.Round != 1) + { + var insigniaIdList = await _dbContext.Set() + .Include(x => x.InsigniaType) + .Where(x => x.InsigniaType!.Name == "ชั้นสายสะพาย") + .Select(x => x.Id) + .ToListAsync(); + + + result_candidate = result_candidate.Where(x => insigniaIdList.Contains(x.RequestInsignia.Id)).ToList(); + } } } else if (type.ToLower().Trim() == "employee") @@ -8327,31 +8365,34 @@ namespace BMA.EHR.Application.Repositories allEmployeeProfileByRoot = (await _userProfileRepository.GetEmployeeProfileByPositionAsync(ocId, period.InsigniaEmployees.Select(x => x.RefId!.ValueOrBlank()).ToArray(), AccessToken)); } - var type_coin = allEmployeeProfileByRoot.Count() > 0 ? await GetCoinCandidate(periodId, ocId, allEmployeeProfileByRoot) : new List(); - - var employee_type1 = allEmployeeProfileByRoot.Count() > 0 ? await GetEmployeeInsignia_Type1(periodId, ocId, allEmployeeProfileByRoot) : new List(); - var employee_type2 = allEmployeeProfileByRoot.Count() > 0 ? await GetEmployeeInsignia_Type2(periodId, ocId, allEmployeeProfileByRoot) : new List(); - - // union result - foreach (var r in type_coin) + if (allEmployeeProfileByRoot != null) { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } + var type_coin = allEmployeeProfileByRoot.Count() > 0 ? await GetCoinCandidate(periodId, ocId, allEmployeeProfileByRoot) : new List(); - foreach (var r in employee_type2) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); - } + var employee_type1 = allEmployeeProfileByRoot.Count() > 0 ? await GetEmployeeInsignia_Type1(periodId, ocId, allEmployeeProfileByRoot) : new List(); + var employee_type2 = allEmployeeProfileByRoot.Count() > 0 ? await GetEmployeeInsignia_Type2(periodId, ocId, allEmployeeProfileByRoot) : new List(); - foreach (var r in employee_type1) - { - var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); - if (old == null) - result_candidate.Add(r); + // union result + foreach (var r in type_coin) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in employee_type2) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } + + foreach (var r in employee_type1) + { + var old = result_candidate.FirstOrDefault(x => x.ProfileId == r.ProfileId); + if (old == null) + result_candidate.Add(r); + } } } else @@ -8571,7 +8612,7 @@ namespace BMA.EHR.Application.Repositories if (period == null) throw new Exception(GlobalMessages.CoinPeriodNotFound); - var inst_profile = allProfilesByRoot.Where(x => x.DateAppoint != null) + var inst_profile = allProfilesByRoot.Where(x => x.DateAppoint.HasValue && x.DateAppoint != null) .Select(p => new { ProfileId = p.Id, @@ -8594,24 +8635,24 @@ namespace BMA.EHR.Application.Repositories Gender = p.Gender ?? "", LastInsignia = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? "" : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().Insignia, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.Insignia, LastInsigniaId = p.ProfileInsignia == null || p.ProfileInsignia.Count == 0 ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) .FirstOrDefault() == null ? Guid.Empty : p.ProfileInsignia - .Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id) - .OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId, + .Where(x => x.InsigniaId.HasValue && x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา")?.Id) + .OrderByDescending(x => x.Year).FirstOrDefault()?.InsigniaId, Salary = p.Amount, SalaryCondition = p.ProfileSalary == null || p.ProfileSalary.Count == 0 ? 0 : - p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) + p.ProfileSalary.Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) .OrderByDescending(x => x.Order).FirstOrDefault() != null ? p.ProfileSalary - .Where(x => x.Date != null).Where(x => x.Date.Value <= new DateTime(period.Year, 4, 29)) - .OrderByDescending(x => x.Order).FirstOrDefault().Amount : + .Where(x => x.Date != null).Where(x => x.Date.HasValue && x.Date.Value <= new DateTime(period.Year, 4, 29)) + .OrderByDescending(x => x.Order).FirstOrDefault()?.Amount : p.Amount, PositionSalaryAmount = p.PositionSalaryAmount, ProfileInsignia = p.ProfileInsignia,