/// <summary> /// Filters our list of tests, based on the parameters that has been given by user. /// </summary> /// <param name="course"></param> /// <param name="grade"></param> public void FilterTests(string course, int grade) { foreach (Test subject in TestList) { if (!MyTests.Contains(subject)) //We check if our filtered list contains Test from original { if (course == "" && subject.Grade == grade) //Make sure that it also matches our choosen course { MyTests.Add(subject); //If not, we add it to the list. } else if (grade == 0 && subject.CourseName == course) { MyTests.Add(subject); } else if (subject.Grade == grade && subject.CourseName == course) { MyTests.Add(subject); } } } foreach (Test filterTest in MyTests.ToList()) //This is if our list is populated with all tests { if (course != "" && filterTest.CourseName != course) { MyTests.Remove(filterTest); } if (grade != 0 && filterTest.Grade != grade) { MyTests.Remove(filterTest); } } }
/// <summary> /// Gets all test from DB and populates list /// </summary> public async void DisplayTests() { TestList = await ApiHelper.Instance.GetAllTests(); foreach (Test t in TestList) { if (!MyTests.Contains(t)) { MyTests.Add(t); } } }
/// <summary> /// Filters our list based on the given course. So we only displays tests related to the course. /// </summary> /// <param name="course"></param> public void FilterListByCourse(string course) { foreach (Test subject in TestList) { if (!MyTests.Contains(subject)) //We check if our filtered list contains Test from original { if (course == "") { MyTests.Add(subject); //If not, we add it to the list. } else if (subject.CourseName == course) { MyTests.Add(subject); } } } }