public PagedList <StudentData> GetGraduateStudentsForUser(int userId, GetPagedListParams parms,
                                                                  bool getBySecretaryForStudent = true)
        {
            var secretaryId = 0;

            if (parms.Filters.ContainsKey("secretaryId"))
            {
                int.TryParse(parms.Filters["secretaryId"], out secretaryId);
            }

            var isStudent           = AuthorizationHelper.IsStudent(Context, userId);
            var isLecturer          = AuthorizationHelper.IsLecturer(Context, userId);
            var isLecturerSecretary = isLecturer && Context.Lecturers.Single(x => x.Id == userId).IsSecretary;

            secretaryId = isLecturerSecretary ? userId : secretaryId;
            if (isStudent)
            {
                if (getBySecretaryForStudent)
                {
                    secretaryId = Context.Users.Where(x => x.Id == userId).Select(x => x.Student.Group.SecretaryId)
                                  .Single() ?? 0;
                }
                else
                {
                    userId = Context.Users.Where(x => x.Id == userId)
                             .Select(x =>
                                     x.Student.AssignedDiplomProjects.FirstOrDefault().DiplomProject.LecturerId)
                             .Single() ?? 0;
                }
            }

            if (string.IsNullOrWhiteSpace(parms.SortExpression) || parms.SortExpression == "Id")
            {
                parms.SortExpression = "Name";
            }
            var query = Context.GetGraduateStudents()
                        .Where(x => isLecturerSecretary || isStudent && getBySecretaryForStudent ||
                               x.AssignedDiplomProjects.Any(asd => asd.DiplomProject.LecturerId == userId))
                        .Where(x => secretaryId == 0 || x.Group.SecretaryId == secretaryId);

            return((from s in query
                    let lecturer = s.AssignedDiplomProjects.FirstOrDefault().DiplomProject.Lecturer
                                   select new StudentData
            {
                Id = s.Id,
                Name = s.LastName + " " + s.FirstName + " " + s.MiddleName,     //todo
                Mark = s.AssignedDiplomProjects.FirstOrDefault().Mark,
                AssignedDiplomProjectId = s.AssignedDiplomProjects.FirstOrDefault().Id,
                Lecturer = lecturer.LastName + " " + lecturer.FirstName + " " + lecturer.MiddleName,     //todo
                Group = s.Group.Name,
                PercentageResults = s.PercentagesResults.Select(pr => new PercentageResultData
                {
                    Id = pr.Id,
                    PercentageGraphId = pr.DiplomPercentagesGraphId,
                    StudentId = pr.StudentId,
                    Mark = pr.Mark,
                    Comment = pr.Comments
                }),
                DipomProjectConsultationMarks = s.DiplomProjectConsultationMarks.Select(cm =>
                                                                                        new DipomProjectConsultationMarkData
                {
                    Id = cm.Id,
                    ConsultationDateId = cm.ConsultationDateId,
                    StudentId = cm.StudentId,
                    Mark = cm.Mark,
                    Comments = cm.Comments
                })
            }).ApplyPaging(parms));
        }
 public void SetStudentDiplomMark(int lecturerId, int assignedProjectId, int mark)
 {
     AuthorizationHelper.ValidateLecturerAccess(Context, lecturerId);
     Context.AssignedDiplomProjects.Single(x => x.Id == assignedProjectId).Mark = mark;
     Context.SaveChanges();
 }