Ejemplo n.º 1
0
        public int GetTotalStudentGradesFromACourse(Course course)
        {
            courseSubjectService = new CourseSubjectService();
            gradeService         = new GradeService();
            studentService       = new StudentService();

            List <Student> studentsRegistered = studentService.GetStudentsRegisteredInACourse(course);

            IEnumerable <StudentSubject> registeredStudentsSubjects = from s in studentsRegistered
                                                                      join ss in db.StudentSubjects
                                                                      on s.ID equals ss.StudentID
                                                                      select ss;

            int sumOfGrades = 0;

            foreach (StudentSubject studentSubject in registeredStudentsSubjects.ToList())
            {
                if (studentSubject.Student.isEnrolled && studentSubject.Grade != null)
                {
                    sumOfGrades = sumOfGrades + gradeService.ConvertGradeToInt(studentSubject.Grade);
                }
            }

            return(sumOfGrades);
        }
Ejemplo n.º 2
0
        public Grade?GetStudentAverageGrade(int id)
        {
            gradeService = new GradeService();

            IEnumerable <Grade?> totalGrades = from ss in db.StudentSubjects.ToList()
                                               join s in db.Students.ToList()
                                               on ss.StudentID equals s.ID
                                               where s.isEnrolled
                                               where s.ID == id
                                               select ss.Grade;

            List <Grade?> realTotalGrades = new List <Grade?>();

            foreach (Grade?grade in totalGrades)
            {
                if (grade.HasValue)
                {
                    realTotalGrades.Add(grade);
                }
            }

            int totalGradesInInt = gradeService.ConvertAllGradesToInt(totalGrades.ToList());

            if (realTotalGrades.ToList().Count != 0)
            {
                decimal average = totalGradesInInt / realTotalGrades.ToList().Count;

                int roundedAverage = (int)Math.Round(average);

                Grade?averageInGrade = gradeService.ConvertIntToGrade(roundedAverage);
            }

            return(null);
        }
Ejemplo n.º 3
0
        public Grade?GetStudentAverageGradePerCourse(Course course)
        {
            studentService        = new StudentService();
            subjectService        = new SubjectService();
            studentSubjectService = new StudentSubjectService();
            gradeService          = new GradeService();

            int   studentsAverageGrade;
            int   studentsAverageRounded;
            Grade?averageGrade;

            List <Subject> subjectsFromACourse = subjectService.GetSubjectsFromACourse(course);

            int numberOfSubjectsInACourse = subjectsFromACourse.Count();

            int numberOfStudentsRegisteredInACourse = studentService
                                                      .GetStudentsRegisteredInACourse(course).Count();

            int studentsTotalGrades = studentSubjectService
                                      .GetTotalStudentGradesFromACourse(course);

            int numberOfStudentSubjectsGraded = GetNumberOfStudentsSubjectsGradedInACourse(subjectsFromACourse);


            if (numberOfSubjectsInACourse != 0 && numberOfStudentSubjectsGraded != 0)
            {
                studentsAverageGrade =
                    studentsTotalGrades / numberOfStudentSubjectsGraded;
            }
            else
            {
                studentsAverageGrade = 0;
            }

            studentsAverageRounded = (int)Math.Round((decimal)studentsAverageGrade);

            averageGrade = gradeService.ConvertIntToGrade(studentsAverageRounded);


            return(averageGrade);
        }
Ejemplo n.º 4
0
        public StudentSubject ChangeGrade(int id, StudentSubject studentSubject)
        {
            gradeService = new GradeService();

            if (gradeService.ConvertGradeToInt(studentSubject.Grade - 2) < 0 ||
                gradeService.ConvertGradeToInt(studentSubject.Grade - 2) > 4)
            {
                return(null);
            }

            StudentSubject newStudentSubject = db.StudentSubjects.Find(id);

            if (newStudentSubject == null)
            {
                return(null);
            }

            newStudentSubject.Grade = studentSubject.Grade;
            db.SaveChanges();

            return(newStudentSubject);
        }