Example #1
0
        public override void Execute()
        {
            if (this.Data.Length != 3)
            {
                throw new InvalidCommandException(this.Input);
            }

            string entityToDisplay = this.Data[1].ToLower();
            string sortType        = this.Data[2].ToLower();

            switch (entityToDisplay)
            {
            case "students":
                IComparer <IStudent>         studentComparator = this.CreateStudentComparator(sortType);
                ISimpleOrderedBag <IStudent> studentList       = this.repository.GetAllStudentsSorted(studentComparator);
                OutputWriter.DisplayStudentMessage(studentList.JoinWith(Environment.NewLine));
                break;

            case "courses":
                IComparer <ICourse>         courseComparator = this.CreateCourseComparator(sortType);
                ISimpleOrderedBag <ICourse> courseList       = this.repository.GetAllCoursesSorted(courseComparator);
                OutputWriter.DisplayCourseMessage(courseList.JoinWith(Environment.NewLine));
                break;

            default:
                throw new InvalidCommandException(this.Input);
            }
        }
 public void GetAllStudentsFromCourse(string courseName)
 {
     if (this.IsQueryForCoursePossible(courseName))
     {
         OutputWriter.DisplayCourseMessage($"{courseName}:");
         foreach (KeyValuePair <string, IStudent> studentMarksEntry in this.courses[courseName].StudentsByName)
         {
             this.GetStudentsScoresFromCourse(courseName, studentMarksEntry.Key);
         }
     }
 }
Example #3
0
        public void GetAllCourses()
        {
            if (!this.isDataInitialized)
            {
                throw new DataException();
            }

            OutputWriter.DisplayCourseMessage($"Number of courses: {this.courses.Count}");
            foreach (KeyValuePair <string, Course> course in this.courses.OrderBy(c => c.Value.Name))
            {
                OutputWriter.DisplayCourseMessage(course.Value.Name);
            }
        }
Example #4
0
        public void GetAllStudents()
        {
            if (!this.isDataInitialized)
            {
                throw new DataException();
            }

            Dictionary <string, Student> allStudents = new Dictionary <string, Student>();

            foreach (KeyValuePair <string, Course> course in this.courses)
            {
                foreach (KeyValuePair <string, Student> student in course.Value.StudentsByName)
                {
                    allStudents.Add(student.Key, student.Value);
                }
            }

            OutputWriter.DisplayCourseMessage($"Number of students: {allStudents.Count}");
            foreach (KeyValuePair <string, Student> student in allStudents.OrderByDescending(s => s.Value.MarksByCourseName.Average(m => m.Value)))
            {
                OutputWriter.DisplayStudentMessage($"{student.Value.Username} - {student.Value.MarksByCourseName.Average(s => s.Value):F2}");
            }
        }