// GET: Students
        public async Task <IActionResult> Index(string firstname, string lastname, string studentid)
        {
            IQueryable <Student> students = _context.Student.AsQueryable();

            if (!string.IsNullOrEmpty(firstname))
            {
                students = students.Where(x => x.FirstName == firstname);
            }
            if (!string.IsNullOrEmpty(lastname))
            {
                students = students.Where(x => x.LastName == lastname);
            }
            if (!string.IsNullOrEmpty(studentid))
            {
                students = students.Where(x => x.StudentId == studentid);
            }
            var studentsSearchVM = new StudentsSearchViewModel
            {
                Students  = await students.ToListAsync(),
                firstName = firstname,
                lastName  = lastname,
                studentId = studentid,
            };

            return(View(studentsSearchVM));
        }
Exemplo n.º 2
0
        // GET: Students
        public async Task <IActionResult> Index(string sFullName, string sStudentId)
        {
            IQueryable <Student> students = _context.Students.AsQueryable();

            if (!string.IsNullOrEmpty(sFullName))
            {
                students = students.Where(s => (s.FirstName + " " + s.LastName).ToLower().Contains(sFullName.ToLower()));
                //students = students.Where(s => s.FullName.ToLower().Contains(sFullName.ToLower()));
            }
            if (!string.IsNullOrEmpty(sStudentId))
            {
                students = students.Where(x => x.StudentId.Contains(sStudentId));
            }
            var studentSearchViewModel = new StudentsSearchViewModel
            {
                Students = await students.ToListAsync()
            };

            System.Console.WriteLine(students.ToString());
            return(View(studentSearchViewModel));
        }