diff --git a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs index a78c2923..11ff2103 100644 --- a/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs +++ b/BMA.EHR.Application/Repositories/InsigniaPeriodsRepository.cs @@ -361,7 +361,13 @@ namespace BMA.EHR.Application.Repositories var jtmRoyal = await _dbContext.Set().FirstOrDefaultAsync(x => x.Name.Contains("จัตุรถาภรณ์มงกุฎไทย")); var s2 = (from p in allProfilesByRoot - where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == bcpRoyal.Id) + where p.ProfileInsignia != null + && p.ProfileInsignia.Count > 0 + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + x.InsigniaId.Value == bcpRoyal.Id) + .ToList() + .Count() == 0) + //where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == bcpRoyal.Id) select new { ProfileId = p.Id, @@ -433,7 +439,13 @@ namespace BMA.EHR.Application.Repositories var s3 = (from p in allProfilesByRoot - where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == jtmRoyal.Id) + where p.ProfileInsignia != null + && p.ProfileInsignia.Count > 0 + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + x.InsigniaId.Value == jtmRoyal.Id) + .ToList() + .Count() == 0) + //where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == jtmRoyal.Id) select new { ProfileId = p.Id, @@ -551,8 +563,8 @@ namespace BMA.EHR.Application.Repositories continue; // Check ว่าชั้นที่ขอสูงกว่าชั้นที่เคยได้รับแล้วหรือไม่? - if (!IsHigherLevel2(r.LastInsignia, r.RequestInsignia.Name)) - continue; + //if (!IsHigherLevel2(r.LastInsignia, r.RequestInsignia.Name)) + // continue; if (old == null) { @@ -666,7 +678,13 @@ namespace BMA.EHR.Application.Repositories var jtmRoyal = await _dbContext.Set().FirstOrDefaultAsync(x => x.Name.Contains("จัตุรถาภรณ์มงกุฎไทย")); var s2 = (from p in allProfilesByRoot - where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == jtmRoyal.Id) + where p.ProfileInsignia != null + && p.ProfileInsignia.Count > 0 + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + x.InsigniaId.Value == jtmRoyal.Id) + .ToList() + .Count() == 0) + //where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == jtmRoyal.Id) select new { ProfileId = p.Id, @@ -738,7 +756,13 @@ namespace BMA.EHR.Application.Repositories .ToList(); var s3 = (from p in allProfilesByRoot - where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == jtcRoyal.Id) + where p.ProfileInsignia != null + && p.ProfileInsignia.Count > 0 + && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != coinInsignia.Id && + x.InsigniaId.Value == jtcRoyal.Id) + .ToList() + .Count() == 0) + //where !(p.ProfileInsignia.Where(x => x.InsigniaId != coinInsignia.Id).OrderByDescending(x => x.Year).FirstOrDefault().InsigniaId == jtcRoyal.Id) select new { ProfileId = p.Id, @@ -856,8 +880,8 @@ namespace BMA.EHR.Application.Repositories continue; // Check ว่าชั้นที่ขอสูงกว่าชั้นที่เคยได้รับแล้วหรือไม่? - if (!IsHigherLevel2(r.LastInsignia, r.RequestInsignia.Name)) - continue; + //if (!IsHigherLevel2(r.LastInsignia, r.RequestInsignia.Name)) + // continue; if (old == null) { @@ -942,12 +966,12 @@ namespace BMA.EHR.Application.Repositories where p.ProfileDateAppoint <= new DateTime(period.Year - 5, 5, 29) && p.LastInsigniaId == Guid.Parse("00000000-0000-0000-0000-000000000000") && p.PositionLevelName == "ปฏิบัติงาน" // ปฏิบัติงาน - && p.ProfileInsignia != null - && p.ProfileInsignia.Count > 0 - && (p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && - x.InsigniaId.Value == GetInsigniaByName("เบญจมาภรณ์มงกุฎไทย").Id) - .ToList() - .Count() == 0) + && p.ProfileInsignia == null + //&& p.ProfileInsignia.Count > 0 + //&& p.ProfileInsignia.Where(x => x.InsigniaId.Value != GetInsigniaByName("เหรียญจักรพรรดิมาลา").Id && + // x.InsigniaId.Value == GetInsigniaByName("เบญจมาภรณ์มงกุฎไทย").Id) + // .ToList() + // .Count() == 0) select p) .ToList() .Select(p => new InsigniaResultSet