public async Task <IActionResult> Index(string studentIndex, string searchString)
        {
            IQueryable <Student> students   = _context.Student.AsQueryable();
            IQueryable <string>  indexQuery = _context.Student.OrderBy(s => s.studentID).Select(s => s.studentID).Distinct();

            if (!string.IsNullOrEmpty(searchString))
            {
                students = students.Where(t => t.firstName.Contains(searchString) || t.lastName.Contains(searchString));
            }
            if (!string.IsNullOrEmpty(studentIndex))
            {
                students = students.Where(x => x.studentID == studentIndex);
            }

            students = students.Include(s => s.Enrollments).ThenInclude(e => e.course);

            var studentNameIndexVM = new StudentNameIndexViewModel
            {
                indexVM   = new SelectList(await indexQuery.ToListAsync()),
                studentVM = await students.ToListAsync()
            };

            return(View(studentNameIndexVM));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(string StudentIndex, string SearchString)
        {
            IQueryable <Student> students   = _context.Student.AsQueryable();
            IQueryable <string>  IndexQuery = _context.Student.OrderBy(s => s.StudentId).Select(s => s.StudentId).Distinct();

            if (!string.IsNullOrEmpty(SearchString))
            {
                students = students.Where(t => t.FirstName.Contains(SearchString) || t.LastName.Contains(SearchString));
            }
            if (!string.IsNullOrEmpty(StudentIndex))
            {
                students = students.Where(x => x.StudentId == StudentIndex);
            }

            students = students.Include(s => s.Courses).ThenInclude(e => e.Course);

            var studentNameIndexVM = new StudentNameIndexViewModel
            {
                IndexVm   = new SelectList(await IndexQuery.ToListAsync()),
                StudentVm = await students.ToListAsync()
            };

            return(View(studentNameIndexVM));
        }