public async Task <IActionResult> Index(string searchStringName, string searchStringSurname, string searchStudentId) { //return View(await _context.Student.ToListAsync()); IQueryable <Student> students = _context.Student.AsQueryable(); if (!string.IsNullOrEmpty(searchStringName)) { students = students.Where(s => s.FirstName.Contains(searchStringName)); } if (!string.IsNullOrEmpty(searchStringSurname)) { students = students.Where(s => s.LastName.Contains(searchStringSurname)); } if (!string.IsNullOrEmpty(searchStudentId)) { students = students.Where(s => s.StudentId.Contains(searchStudentId)); } var studentNameIdVM = new StudentNameIdViewModel { Students = await students.ToListAsync() }; return(View(studentNameIdVM)); }
public async Task <IActionResult> StudentIndex(string StudentName, string StudentIDs) { IQueryable <Student> students = _context.Student.AsQueryable(); IQueryable <string> IDQuery = _context.Student.OrderBy(m => m.StudentId).Select(m => m.StudentId).Distinct(); if (!string.IsNullOrEmpty(StudentName)) { students = students.Where(s => s.FirstName.Contains(StudentName) || s.LastName.Contains(StudentName)); } if (!string.IsNullOrEmpty(StudentIDs)) { students = students.Where(x => x.StudentId == StudentIDs); } //students = students.Include(s => s.Courses).ThenInclude(s => s.Course); var studentnameVM = new StudentNameIdViewModel { IDs = new SelectList(await IDQuery.ToListAsync()), Students = await students.ToListAsync() }; return(View(studentnameVM));; }