Example #1
0
        public IEnumerable <RptCovid19ExViewModel> Search(RptCovidTravelSearchViewModel condition)
        {
            var filteredData = context.RPT_COVID19EX.Select(o => o.PERSON_ID).Distinct()
                               .SelectMany(key => context.RPT_COVID19EX.Join(context.EMPLOYEE, covid => covid.PERSON_ID, e => e.PERSON_ID, (covid, e) => new { covid, e })
                                           .Select(o => new { o.e.PERSON_ID, o.e.FULLNAME, o.covid.CREATED_DT, o.covid.HAS_FLU, o.covid.TRAVEL_FLAG })
                                           .Where(x => x.PERSON_ID == key).OrderByDescending(x => x.CREATED_DT).Take(1));

            //filter data
            if (!string.IsNullOrEmpty(condition.PERSON_ID))
            {
                filteredData = filteredData.Where(o => o.PERSON_ID.Contains(condition.PERSON_ID));
            }

            if (!string.IsNullOrEmpty(condition.NAME))
            {
                filteredData = filteredData.Where(o => o.FULLNAME.Contains(condition.NAME));
            }

            if (!string.IsNullOrEmpty(condition.HAS_FLU) && condition.HAS_FLU != "99")
            {
                filteredData = filteredData.Where(o => o.HAS_FLU == (condition.HAS_FLU == "1" ? "มีไข้" : "ไม่มีไข้"));
            }

            //แปลข้อมูลให้อยู่ในรูปแบบ json
            var culture = new CultureInfo("th-TH");

            var query = filteredData.ToList().Select(o => new RptCovid19ExViewModel()
            {
                PERSON_ID  = o.PERSON_ID,
                FULLNAME   = o.FULLNAME,
                ReportDate = o.CREATED_DT.HasValue ? o.CREATED_DT.Value.ToString("dd/MM/yyyy HH:mm น.", culture) : "",
            });

            return(query.ToList());
        }
        public ActionResult Index(string id)
        {
            RptCovidTravelSearchViewModel condition = new RptCovidTravelSearchViewModel();

            condition.HAS_FLU = id;
            return(View(condition));
        }
 public ActionResult Search(RptCovidTravelSearchViewModel condition)
 {
     try
     {
         return(Json(model.Search(condition)));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }));
     }
 }