diff --git a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs index ee347123..f0a754d0 100644 --- a/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs +++ b/BMA.EHR.Discipline.Service/Controllers/DisciplineResultController.cs @@ -739,11 +739,149 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers return Success(data1); } + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-19 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command19/report")] + public async Task> PostReportCommand19([FromBody] ReportPersonRequest req) + { + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + /// + /// ออกคำสั่ง C-PM-19 คำสั่งปลดออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command19/report/excecute")] + public async Task> PostReportCommand19Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + 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 = true, + leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ", + dateLeave = r.commandAffectDate, + 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 + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } + /// + /// ส่งรายชื่อออกคำสั่ง C-PM-20 + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command20/report")] + public async Task> PostReportcommand20([FromBody] ReportPersonRequest req) + { + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); + return Success(); + } + /// + /// ออกคำสั่ง C-PM-20 คำสั่งไล่ออกจากราชการ + /// + /// + /// + /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command20/report/excecute")] + public async Task> PostReportCommand20Execute([FromBody] ReportExecuteRequest req) + { + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Include(x => x.DisciplineDisciplinary) + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); + var resultData = (from p in data + 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 = true, + leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ", + dateLeave = r.commandAffectDate, + 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 + { + data = resultData, + }); + var _result = await _res.Content.ReadAsStringAsync(); + if (_res.IsSuccessStatusCode) + { + data.ForEach(profile => { profile.Status = "NEW"; profile.CommandTypeId = null; }); + await _context.SaveChangesAsync(); + } + } + return Success(); + } /// /// ส่งรายชื่อออกคำสั่ง C-PM-25 @@ -758,24 +896,6 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers { try { - // var resultData = new List(); - // var baseAPI = _configuration["API"]; - - // foreach (var id in req_.refIds) - // { - // var apiUrl = $"{baseAPI}/discipline/result/report/stop/{id}"; - - // } - // var data = await _context.DisciplineReport_Profiles - // .Where(x => x.Status == "REPORT") - // .Where(x => x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id == id) - // .Select(x => new - // { - // PersonId = x.PersonId, - // Id = x.Id, - // CommandId = x.CommandTypeId, - // }) - // .ToListAsync(); var data = await _context.DisciplineReport_Profiles .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); @@ -807,33 +927,24 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers { try { - foreach (var d in req.refIds) - { - var apiUrl = $"{_configuration["API"]}/discipline/result/report/find/{d.refId}"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var _res = await client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); + var data = await _context.DisciplineReport_Profiles + .Where(x => x.Status == "REPORT") + .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) + .ToListAsync(); - var org = JsonConvert.DeserializeObject(_result); + var resultData = (from p in data + join r in req.refIds + on p.Id.ToString() equals r.refId + select new + { + fullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + positionname = p.Position, + positionno = p.PosNo, + organizationname = p.Organization, + salary = r.Amount + }).ToList(); - if (org == null || org.result == null) - continue; - var receiver = new CommandType23Response - { - fullName = $"{d.Prefix}{d.FirstName} {d.LastName}", - positionname = org.result.position, - positionno = org.result.posNo == null ? null : org.result.posNo.ToThaiNumber(), - organizationname = org.result.organization, - salary = org.result.salary == null ? null : org.result.salary.Value.ToNumericNoDecimalText().ToString(), - }; - - return Success(receiver); - } - } - return null; + return Success(resultData); } catch { @@ -904,68 +1015,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command26/report")] - public async Task> PostReportCommand26([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand26([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; - - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/stop/{id}"; - - var commandType = await _context.Set() - .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-26") - .FirstOrDefaultAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); - - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - if (commandType == null || commandType.Id != d.commandId) - continue; - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + var data = await _context.DisciplineReport_Profiles + .Where(x => req.refIds.Contains(x.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); return Success(); } catch @@ -1038,68 +1096,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command27/report")] - public async Task> PostReportCommand27([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand27([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; - - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/up/{id}"; - - var commandType = await _context.Set() - .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-27") - .FirstOrDefaultAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); - - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - if (commandType == null || commandType.Id != d.commandId) - continue; - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); return Success(); } catch @@ -1171,68 +1176,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command28/report")] - public async Task> PostReportCommand28([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand28([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; - - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/up/{id}"; - - var commandType = await _context.Set() - .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-28") - .FirstOrDefaultAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); - - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - if (commandType == null || commandType.Id != d.commandId) - continue; - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); return Success(); } catch @@ -1304,68 +1256,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command29/report")] - public async Task> PostReportCommand29([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand29([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; - - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/up/{id}"; - - var commandType = await _context.Set() - .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-29") - .FirstOrDefaultAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); - - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - if (commandType == null || commandType.Id != d.commandId) - continue; - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); return Success(); } catch @@ -1437,68 +1336,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command30/report")] - public async Task> PostReportCommand30([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand30([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; - - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/up/{id}"; - - var commandType = await _context.Set() - .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-30") - .FirstOrDefaultAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); - - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - if (commandType == null || commandType.Id != d.commandId) - continue; - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); return Success(); } catch @@ -1570,68 +1416,15 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command31/report")] - public async Task> PostReportCommand31([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand31([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; - - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/up/{id}"; - - var commandType = await _context.Set() - .Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-31") - .FirstOrDefaultAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); - - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - if (commandType == null || commandType.Id != d.commandId) - continue; - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); + data.ForEach(profile => profile.Status = "REPORT"); + await _context.SaveChangesAsync(); return Success(); } catch @@ -1703,63 +1496,22 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("command32/report")] - public async Task> PostReportCommand32([FromBody] ReportPersonRequest req_) + public async Task> PostReportCommand32([FromBody] ReportPersonRequest req) { try { - var resultData = new List(); - var baseAPI = _configuration["API"]; + var data1 = await _context.DisciplineInvestigate_ProfileComplaints + .Where(x => req.refIds.Contains(x.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); - foreach (var id in req_.refIds) - { - var apiUrl = $"{baseAPI}/discipline/result/report/reject/{id}"; + data1.ForEach(profile => profile.IsReport = "REPORT"); + var data2 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates + .Where(x => req.refIds.Contains(x.DisciplineDisciplinary.DisciplineInvestigate.DisciplineComplaint.Id.ToString())) + .ToListAsync(); - var response = new PassDisciplineResponse(); - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var req = new HttpRequestMessage(HttpMethod.Get, apiUrl); - var res = await client.SendAsync(req); - var result = await res.Content.ReadAsStringAsync(); + data2.ForEach(profile => profile.IsReport = "REPORT"); - response = JsonConvert.DeserializeObject(result); - - var seq = 1; - foreach (var d in response!.result) - { - var _baseAPI = _configuration["API"]; - var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}"; - using (var _client = new HttpClient()) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); - _client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl); - var _res = await _client.SendAsync(_req); - var _result = await _res.Content.ReadAsStringAsync(); - - var org = JsonConvert.DeserializeObject(_result); - - if (org == null || org.result == null) - continue; - - var receiver = new CommandReceiver - { - Sequence = seq, - CitizenId = org.result.citizenId == null ? "" : org.result.citizenId, - Prefix = org.result.prefix == null ? "" : org.result.prefix, - FirstName = org.result.firstName == null ? "" : org.result.firstName, - LastName = org.result.lastName == null ? "" : org.result.lastName, - RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId), - RefDisciplineId = d.id, - Amount = 0, - }; - seq++; - resultData.Add(receiver); - } - } - } - } + await _context.SaveChangesAsync(); return Success(); } catch