public IActionResult OngetOpmUser(string id) { var user = _userManager.Users.Where(m => m.Id == id) // .Include(m => m.Departments) //.ThenInclude(m=>m.) .FirstOrDefault(); var userProvince = _context.UserProvinces .Where(user => user.UserID == id) // .Where(p => p.ProvinceId == 1) // .Select(s => s.ProvinceId) .ToList(); List <OpmUserProvince> opmUserProvincesAll = new List <OpmUserProvince>(); foreach (var item in userProvince) { var Province = _context.Provinces .Where(w => w.Id == item.ProvinceId) .First(); ProvinceKeyword ProvinceS = SearchProvince(Province.Name); Console.WriteLine(ProvinceS.Id); var prov = new { province = Province.Name }; List <OpmUserProvince> opmUserProvinces = OpmOpmUserProvince(ProvinceS.Id); for (int i = 0; i < opmUserProvinces.Count; i++) { opmUserProvincesAll.Add(opmUserProvinces[i]); } } OpmUserProvince[] terms = opmUserProvincesAll.ToArray(); return(Ok(terms)); }
public ProvinceKeyword SearchProvince(string provinceName) { ProvinceKeyword ProvinceS = null; var client = new HttpClient(); var task = client.GetAsync("http://203.113.14.20:3000/testservice/opm/province/key/ " + provinceName) .ContinueWith((taskwithresponse) => { var response = taskwithresponse.Result; var jsonString = response.Content.ReadAsStringAsync(); jsonString.Wait(); ProvinceS = JsonConvert.DeserializeObject <ProvinceKeyword>(jsonString.Result); }); task.Wait(); return(ProvinceS); }
public IActionResult excelfiscalyear(string id) { var user = _userManager.Users.Where(m => m.Id == id) .FirstOrDefault(); var userProvince = _context.UserProvinces .Where(user => user.UserID == id) .ToList(); List <OpmUserProvince> opmUserProvincesAll = new List <OpmUserProvince>(); foreach (var item in userProvince) { var Province = _context.Provinces .Where(w => w.Id == item.ProvinceId) .First(); ProvinceKeyword ProvinceS = SearchProvince(Province.Name); Console.WriteLine(ProvinceS.Id); var prov = new { province = Province.Name }; List <OpmUserProvince> opmUserProvinces = OpmOpmUserProvince(ProvinceS.Id); for (int i = 0; i < opmUserProvinces.Count; i++) { opmUserProvincesAll.Add(opmUserProvinces[i]); } } OpmUserProvince[] terms = opmUserProvincesAll.ToArray(); using (var workbook = new XLWorkbook()) { var worksheet = workbook.Worksheets.Add("opm-1111"); var currentRow2 = 1; worksheet.Cell(currentRow2, 1).Value = "รหัส"; worksheet.Cell(currentRow2, 2).Value = "วัตถุประสงค์"; worksheet.Cell(currentRow2, 3).Value = "วันที่รับแจ้ง"; worksheet.Cell(currentRow2, 4).Value = "ประเภทเรื่อง"; worksheet.Cell(currentRow2, 5).Value = "สาระสำคัญ"; foreach (var item in terms) { currentRow2++; worksheet.Cell(currentRow2, 1).Value = item.CaseCode; worksheet.Cell(currentRow2, 2).Value = item.ObjectiveText; worksheet.Cell(currentRow2, 3).Value = item.DateOpened; worksheet.Cell(currentRow2, 4).Value = item.TypeText; worksheet.Cell(currentRow2, 5).Value = item.Summary; } using (var stream = new MemoryStream()) { workbook.SaveAs(stream); var content = stream.ToArray(); return(File( content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ข้อมูลเรื่องร้องเรียนจากระบบศูนย์รับเรื่องราวร้องทุกข์ของรัฐบาล.xlsx")); } } }