Ejemplo n.º 1
0
        public IActionResult OnGet(int?id, int p = 1, StudentSortState sortState = StudentSortState.FacultyNameAsc)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var tournament = tournamentRepository.GetTournament(id.Value);

            if (tournament == null)
            {
                return(NotFound());
            }

            int size = 25;

            var students          = userRepository.GetStudents(p, size, sortState);
            var studentsViewModel = new List <StudentEntityViewModel>();

            foreach (var item in students)
            {
                studentsViewModel.Add(new StudentEntityViewModel(item, id.Value));
            }

            ViewModel = new StudentsViewModel
            {
                TournamentId   = tournament.TournamentId,
                TournamentName = tournament.Name,
                SortViewModel  = new StudentsSortViewModel(sortState),
                Students       = studentsViewModel,
                PageViewModel  = new PageViewModel(studentsViewModel.Count(), p, size)
            };

            return(Page());
        }
Ejemplo n.º 2
0
        public IEnumerable <ApplicationUser> GetStudents(StudentSortState sortState)
        {
            var students = GetStudentsQuery();

            students = ApplySort(students, sortState);

            return(students.ToList());
        }
Ejemplo n.º 3
0
        public StudentsSortViewModel(StudentSortState sortState)
        {
            YearNo         = sortState == StudentSortState.YearNoAsc ? StudentSortState.YearNoDesc : StudentSortState.YearNoAsc;
            FacultyName    = sortState == StudentSortState.FacultyNameAsc ? StudentSortState.FacultyNameDesc : StudentSortState.FacultyNameAsc;
            LecternName    = sortState == StudentSortState.LecternNameAsc ? StudentSortState.LecternNameDesc : StudentSortState.LecternNameAsc;
            CurriculumName = sortState == StudentSortState.CurriculumNameAsc ? StudentSortState.CurriculumNameDesc : StudentSortState.CurriculumNameAsc;
            Degree         = sortState == StudentSortState.DegreeAsc ? StudentSortState.DegreeDesc : StudentSortState.DegreeAsc;

            Current = sortState;
        }
Ejemplo n.º 4
0
        public IEnumerable <ApplicationUser> GetStudents(int p, int size, StudentSortState sortState)
        {
            var students = GetStudentsQuery();

            students = ApplySort(students, sortState);

            var items = Paginate(students, p, size);

            return(items);
        }
Ejemplo n.º 5
0
        public IActionResult OnPostApply(int?id, int p = 1, StudentSortState sortState = StudentSortState.FacultyNameAsc)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            var tournament = tournamentRepository.GetTournament(id.Value);

            if (tournament == null)
            {
                return(NotFound());
            }

            if (ViewModel.Students.Any(x => x.ValueChanged))
            {
                foreach (var item in ViewModel.Students.Where(x => x.ValueChanged))
                {
                    var student = userRepository.GetStudent(item.Id);
                    if (item.HasBeenChacked)
                    {
                        StudentTournament st = new StudentTournament
                        {
                            ApplicationUser   = student,
                            ApplicationUserId = student.Id,
                            Tournament        = tournament,
                            TournamentId      = tournament.TournamentId
                        };

                        studentTournamentRepository.Add(st);
                        student.Tournaments.Add(st);
                        userRepository.Update(student);
                        tournament.Assignees.Add(st);
                        tournamentRepository.Update(tournament);
                    }
                    else if (item.HasBeenUnChacked)
                    {
                        var st = studentTournamentRepository.Get(student.Id, tournament.TournamentId);

                        if (st != null)
                        {
                            studentTournamentRepository.Remove(st);
                        }
                    }
                }
            }

            return(OnGet(id, p, sortState));
        }
Ejemplo n.º 6
0
 public IActionResult OnPostDone(int?id, int p = 1, StudentSortState sortState = StudentSortState.FacultyNameAsc)
 {
     return(OnGet(id, p, sortState));
 }
Ejemplo n.º 7
0
        private IQueryable <ApplicationUser> ApplySort(IQueryable <ApplicationUser> users, StudentSortState sortState)
        {
            switch (sortState)
            {
            case StudentSortState.YearNoAsc:
                users = users.OrderBy(x => x.YearNo);
                break;

            case StudentSortState.YearNoDesc:
                users = users.OrderByDescending(x => x.YearNo);
                break;

            case StudentSortState.FacultyNameAsc:
                users = users.OrderBy(x => x.Faculty.Name);
                break;

            case StudentSortState.FacultyNameDesc:
                users = users.OrderByDescending(x => x.Faculty.Name);
                break;

            case StudentSortState.LecternNameAsc:
                users = users.OrderBy(x => x.Lectern.Name);
                break;

            case StudentSortState.LecternNameDesc:
                users = users.OrderByDescending(x => x.Lectern.Name);
                break;

            case StudentSortState.CurriculumNameAsc:
                users = users.OrderBy(x => x.Сurriculum.Name);
                break;

            case StudentSortState.CurriculumNameDesc:
                users = users.OrderByDescending(x => x.Сurriculum.Name);
                break;

            case StudentSortState.DegreeAsc:
                users = users.OrderBy(x => x.DegreeType);
                break;

            case StudentSortState.DegreeDesc:
                users = users.OrderByDescending(x => x.DegreeType);
                break;
            }

            return(users);
        }