/// <summary> /// Gets students but also does filtering query on them /// </summary> /// <param name="courseName"></param> /// <param name="sorting">Choose either Filtering or Ordering</param> /// <param name="criteria">Filtering - by performance, Sorting - Ascending, Descending</param> /// <param name="takeNumber">Amount of items to take</param> public void GetAllStudentsFromCourse(string courseName, SortingOperation sorting, string criteria = null, int takeNumber = -1) { if (sorting == SortingOperation.None) { GetAllStudentsFromCourse(courseName); } else if (IsQueryForCoursePossible(courseName)) { //Extract the student names and their marks var studentsWithMarks = courses[courseName].StudentsByName.ToDictionary(k => k.Key, v => v.Value.MarksByCourseName[courseName]); if (sorting == SortingOperation.Filter) { studentsWithMarks = filter.FilterAndTake(studentsWithMarks, criteria, takeNumber) as Dictionary <string, double>; } else if (sorting == SortingOperation.Order) { studentsWithMarks = sorter.OrderAndTake(studentsWithMarks, criteria, takeNumber) as Dictionary <string, double>; } if (studentsWithMarks is null) { return; } foreach (var student in studentsWithMarks) { OutputWriter.PrintStudent(student); } } }
public QuerySorter(string field, SortingOperation sortingOperation) { ConditionChecker.Requires(string.IsNullOrEmpty(field) == false); this.Field = field; this.SortingOperation = sortingOperation; }