/// <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> /// Send Test.Id of the test to ApiHelper to delete it from db /// </summary> /// <param name="id"></param> public void DeleteTest(int id) { ApiHelper.Instance.DeleteTest(id); foreach (Test t in MyTests.ToList()) { if (t.TestId == id) { MyTests.Remove(t); TestList.Remove(t); } } }