コード例 #1
0
        public ViewResult Index(string currentFilter, string searchString, int?page, string gqwGroup, SortState sortOrder = SortState.NameAsc)
        {
            ViewBag.Message = "Список выпускных квалификационных работ";

            IQueryable <Gqw> gqws = university.Gqw
                                    .Include(x => x.Graduate)
                                    .Include(y => y.Reviewer)
                                    .Include(z => z.Teacher)
                                    .Include(w => w.Sec);

            ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["ArchSort"] = sortOrder == SortState.ArchAsc ? SortState.ArchDesc : SortState.ArchAsc;


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

            ViewBag.CurrentFilter = searchString;

            if (!String.IsNullOrEmpty(searchString))
            {
                gqws = gqws.Where(s => s.Graduate.LastName.Contains(searchString) ||
                                  s.Graduate.FirstName.Contains(searchString) ||
                                  s.Graduate.Patronymic.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(gqwGroup))
            {
                gqws = gqws.Where(x => x.Graduate.Group.Name == gqwGroup);
            }

            gqws = sortOrder switch
            {
                SortState.NameDesc => gqws.OrderByDescending(s => s.Graduate.LastName),
                SortState.ArchAsc => gqws.OrderBy(s => s.IsArchived),
                SortState.ArchDesc => gqws.OrderByDescending(s => s.IsArchived),
                _ => gqws.OrderBy(s => s.Graduate.LastName),
            };

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(gqws.ToPagedList(pageNumber, pageSize)));
        }
コード例 #2
0
        public ViewResult Index(string currentFilter, string searchString, int?page, string graduateGroup, SortState sortOrder = SortState.NameAsc)
        {
            ViewBag.Message = "Список выпускников";

            IQueryable <Graduate> graduates = university.Graduate
                                              .Include(x => x.Group)
                                              .Include(y => y.Company)
                                              .Include(z => z.AcademicDegree);

            ViewData["NameSort"]    = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc;
            ViewData["GroupSort"]   = sortOrder == SortState.GroupAsc ? SortState.GroupDesc : SortState.GroupAsc;
            ViewData["LectSort"]    = sortOrder == SortState.LectAsc ? SortState.LectDesc : SortState.LectDesc;
            ViewData["LabSort"]     = sortOrder == SortState.LabAsc ? SortState.LabDesc : SortState.LabDesc;
            ViewData["CitySort"]    = sortOrder == SortState.CityAsc ? SortState.CityDesc : SortState.CityAsc;
            ViewData["CompanySort"] = sortOrder == SortState.CompanyAsc ? SortState.CompanyDesc : SortState.CompanyAsc;
            ViewData["DegreeSort"]  = sortOrder == SortState.DegreeAsc ? SortState.DegreeDesc : SortState.DegreeAsc;

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

            ViewBag.CurrentFilter = searchString;

            if (!String.IsNullOrEmpty(searchString))
            {
                graduates = graduates.Where(s => s.LastName.Contains(searchString) ||
                                            s.FirstName.Contains(searchString) ||
                                            s.Patronymic.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(graduateGroup))
            {
                graduates = graduates.Where(x => x.Group.Name == graduateGroup);
            }

            graduates = sortOrder switch
            {
                SortState.NameDesc => graduates.OrderByDescending(s => s.LastName),
                SortState.GroupAsc => graduates.OrderBy(s => s.Group.Name),
                SortState.GroupDesc => graduates.OrderByDescending(s => s.Group.Name),
                SortState.LectDesc => graduates.OrderByDescending(s => s.DisciplineLecture),
                SortState.LectAsc => graduates.OrderBy(s => s.DisciplineLecture),
                SortState.LabDesc => graduates.OrderByDescending(s => s.DisciplineLaboratoryWorks),
                SortState.LabAsc => graduates.OrderBy(s => s.DisciplineLaboratoryWorks),
                SortState.CityDesc => graduates.OrderByDescending(s => s.CurrentCity),
                SortState.CityAsc => graduates.OrderBy(s => s.CurrentCity),
                SortState.CompanyDesc => graduates.OrderByDescending(s => s.Company),
                SortState.CompanyAsc => graduates.OrderBy(s => s.Company),
                SortState.DegreeDesc => graduates.OrderByDescending(s => s.AcademicDegree),
                SortState.DegreeAsc => graduates.OrderBy(s => s.AcademicDegree),
                _ => graduates.OrderBy(s => s.LastName),
            };

            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            return(View(graduates.ToPagedList(pageNumber, pageSize)));
        }