public object listAllexam(string text_search, string status_search, string group_search, string subject_search, string from_search, string to_search, int?move_from, int pageno = 1) { /*repair test student exam*/ var curdate = DateUtil.Now().Date; var rtstudents = _context.TestResultStudents.Include(i => i.Test).Where(w => w.ExamingStatus == ExamingStatus.Examing); foreach (var rtstudent in rtstudents) { if (rtstudent.Test != null) { var remain = FuncUtil.GetTimeRemaining(rtstudent.Test.TimeLimitType, rtstudent.Test.TimeLimit, rtstudent.Start_On); if (remain <= 0) { rtstudent.ExamingStatus = ExamingStatus.Done; rtstudent.Other = true; rtstudent.Update_On = curdate; rtstudent.End_On = rtstudent.Start_On.Value.AddSeconds(FuncUtil.GetMaxTimeLimit(rtstudent.Test.TimeLimitType, rtstudent.Test.TimeLimit)); } } } _context.SaveChanges(); var exam = _context.Exams.Include(i => i.Test).Include(i => i.Subject).Include(i => i.Subject.SubjectGroup).Where(w => 1 == 1); if (move_from.HasValue) { exam = exam.Where(w => w.ID != move_from & w.ExamDate.Value >= curdate.Date); } if (!string.IsNullOrEmpty(status_search)) { exam = exam.Where(w => w.Status == status_search.toStatus()); } if (!string.IsNullOrEmpty(subject_search)) { var subjectID = NumUtil.ParseInteger(subject_search); if (subjectID > 0) { exam = exam.Where(w => w.SubjectID == subjectID); } } if (!string.IsNullOrEmpty(group_search)) { var groupID = NumUtil.ParseInteger(group_search); if (groupID > 0) { exam = exam.Where(w => w.Subject.SubjectGroupID == groupID); } } if (!string.IsNullOrEmpty(from_search)) { var date = DateUtil.ToDate(from_search); exam = exam.Where(w => w.ExamDate.Value.Date >= date); } if (!string.IsNullOrEmpty(to_search)) { var date = DateUtil.ToDate(to_search); exam = exam.Where(w => w.ExamDate.Value.Date <= date); } var exams = new List <Exam>(); if (!string.IsNullOrEmpty(text_search)) { var text_splits = text_search.Split(",", StringSplitOptions.RemoveEmptyEntries); foreach (var text_split in text_splits) { if (!string.IsNullOrEmpty(text_split)) { var text = text_split.Trim(); var registerIDs = _context.ExamRegisters.Where(w => w.Student.FirstName.Contains(text) | w.Student.LastName.Contains(text) | w.Student.FirstNameEn.Contains(text) | w.Student.LastNameEn.Contains(text) | w.Student.IDCard.Contains(text) | w.Student.Phone.Contains(text) | w.Student.Email.Contains(text) | w.Student.Passport.Contains(text) | w.Student.StudentCode.Contains(text) | (w.Student.FirstName + " " + w.Student.LastName).Contains(text) | (w.Student.FirstNameEn + " " + w.Student.LastNameEn).Contains(text) ).Select(s => s.ExamID); exams.AddRange(exam.Where(w => w.Test.Name.Contains(text) | w.ExamCode.Contains(text) | registerIDs.Contains(w.ID) )); } } exams = exams.Distinct().ToList(); } else { exams = exam.ToList(); } int skipRows = (pageno - 1) * 25; var itemcnt = exams.Count(); var pagelen = itemcnt / 25; if (itemcnt % 25 > 0) { pagelen += 1; } return(CreatedAtAction(nameof(listAllexam), new { data = exams.Select(s => new { id = s.ID, test = s.ExamTestType == ExamTestType.Random ? _context.Tests.Where(w => w.SubjectID == s.SubjectID & w.Status == StatusType.Active).Count() == 1 ? _context.Tests.Where(w => w.SubjectID == s.SubjectID & w.Status == StatusType.Active).FirstOrDefault().Name : "สุ่ม" : s.Test.Name, status = s.Status.toStatusName(), group = s.Subject.SubjectGroup.Name, subject = s.Subject.Name, subjectorder = s.Subject.Order, examcode = s.ExamCode, examdate = DateUtil.ToDisplayDate(s.ExamDate), date = s.ExamDate, examperiod = s.ExamPeriod.toExamPeriodName(), examperiodid = s.ExamPeriod, examtesttype = s.ExamTestType.toExamTestType(), registercnt = s.RegisterCnt, examregistercnt = s.ExamRegisterCnt, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderByDescending(o => o.date).ThenBy(o => o.examperiodid).ThenBy(o => o.group).ThenBy(o => o.subjectorder).Skip(skipRows).Take(25).ToArray(), pagelen = pagelen, itemcnt = itemcnt, }));; }