From dd170565b5292bd81d951cc9320be15c8c510b41 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 4 Oct 2024 16:10:37 +0700 Subject: [PATCH] no message --- .../Controllers/DisciplineResultController.cs | 113 ++++++++---------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs index 025c78c1..ee347123 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs @@ -1785,10 +1785,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); string? _null = null; - dynamic? resultData = null; - if (data.Count != 0) - { - resultData = (from p in data + var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId select new @@ -1805,67 +1802,63 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers level = "", unStigma = "คำสั่งยุติเรื่อง" }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data.ForEach(profile => profile.IsReport = "NEW"); - await _context.SaveChangesAsync(); - } - } - } - else + var baseAPIOrg = _configuration["API"]; + var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; + using (var client = new HttpClient()) { - var data1 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates - .Include(x => x.DisciplineDisciplinary) - .Where(x => x.IsReport == "REPORT") - .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) - .ToListAsync(); - resultData = (from p in data1 - join r in req.refIds - on p.Id.ToString() equals r.refId - select new - { - profileId = p.PersonId, - date = r.commandAffectDate, - refCommandNo = $"{r.commandNo}/{r.commandYear}", - salaryRef = r.templateDoc, - isLeave = false, - leaveReason = _null, - dateLeave = _null, - refCommandDate = DateTime.Now, - detail = p.DisciplineDisciplinary.Title, - level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, - unStigma = "คำสั่งยุติเรื่อง" - }).ToList(); - var baseAPIOrg = _configuration["API"]; - var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave-discipline"; - using (var client = new HttpClient()) + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _res = await client.PostAsJsonAsync(apiUrlOrg, new - { - data = resultData, - }); - var _result = await _res.Content.ReadAsStringAsync(); - if (_res.IsSuccessStatusCode) - { - data1.ForEach(profile => profile.IsReport = "NEW"); - await _context.SaveChangesAsync(); - } + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => profile.IsReport = "NEW"); + await _context.SaveChangesAsync(); } } + var data1 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => x.IsReport == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData1 = (from p in data1 + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + profileId = p.PersonId, + date = r.commandAffectDate, + refCommandNo = $"{r.commandNo}/{r.commandYear}", + salaryRef = r.templateDoc, + isLeave = false, + leaveReason = _null, + dateLeave = _null, + refCommandDate = DateTime.Now, + detail = p.DisciplineDisciplinary.Title, + level = p.DisciplineDisciplinary.DisciplinaryFaultLevel, + unStigma = "คำสั่งยุติเรื่อง" + }).ToList(); + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + var _res = await client.PostAsJsonAsync(apiUrlOrg, new + { + data = resultData1, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data1.ForEach(profile => profile.IsReport = "NEW"); + await _context.SaveChangesAsync(); + } + } + + return Success(); } }