Exemple #1
0
        public async Task OnGetAsync(string sortOrder, string searchString,
                                     string currentFilter, int?pageIndex)
        {
            CurrentSort = sortOrder;
            NameSort    = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            DateSort    = sortOrder == "Date" ? "date_desc" : "Date";

            if (searchString != null)
            {
                pageIndex = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            CurrentFilter = searchString;

            IQueryable <Student> studentIQ = from s in _context.Students select s;

            if (!String.IsNullOrEmpty(searchString))
            {
                studentIQ = studentIQ.Where(s => s.LastName.Contains(searchString) ||
                                            s.FirstMidName.Contains(searchString));
            }

            switch (sortOrder)
            {
            case "name_desc":
                studentIQ = studentIQ.OrderByDescending(s => s.LastName);
                break;

            case "Date":
                studentIQ = studentIQ.OrderBy(s => s.EnrollmentDate);
                break;

            case "date_desc":
                studentIQ = studentIQ.OrderByDescending(s => s.EnrollmentDate);
                break;

            default:
                studentIQ = studentIQ.OrderBy(s => s.LastName);
                break;
            }

            int pageSize = 3;

            Student = await PaginatedList <Student> .CreateAsynq(
                studentIQ.AsNoTracking(), pageIndex ?? 1, pageSize);
        }