Exemple #1
0
 public void RemoveFaculty(Faculty facultyToRemove)
 {
     if (Faculties.Contains(facultyToRemove))
     {
         Faculties.Remove(facultyToRemove);
     }
 }
        public SearchFilter ApplyFilter()
        {
            if (CityName == "" && FacultyName == "" && ProfessorName == "" && MinReview == 0 && MaxReview == Int16.MaxValue)
            {
                return(this);
            }

            if (CityName != "")
            {
                Cities    = Cities.Where(city => city.Name.ToLower().Contains(CityName.ToLower()));
                Faculties = Cities.SelectMany(c => c.Universities).SelectMany(u => u.Faculties);
                Subjects  = Subjects.Where(s => Faculties.Contains(s.Faculty));
                var professors = Subjects.SelectMany(s => s.Professors).Select(s => s.Professor);
                Professors = Professors.Where(p => professors.Contains(p));
            }
            if (FacultyName != "")
            {
                Faculties = Faculties.Where(faculty => faculty.Name.ToLower().Contains(FacultyName.ToLower()));
                Subjects  = Subjects.Where(s => Faculties.Contains(s.Faculty));
                var professors = Subjects.SelectMany(s => s.Professors).Select(s => s.Professor);
                Professors = Professors.Where(p => professors.Contains(p));
            }
            if (ProfessorName != "")
            {
                Professors = Professors.Where(professor => professor.FullName.ToLower().Contains(ProfessorName.ToLower()));
                var subjects = Professors.SelectMany(p => p.Subjects).Select(p => p.Subject);
                Subjects = Subjects.Where(s => subjects.Contains(s));
            }
            if (MinReview.HasValue)
            {
                Professors = Professors.Where(professor => professor.Reviews.Count >= MinReview);
                Subjects   = Subjects.Where(subject => subject.Reviews.Count >= MinReview);
            }
            if (MaxReview.HasValue)
            {
                Professors = Professors.Where(professor => professor.Reviews.Count <= MaxReview);
                Subjects   = Subjects.Where(subject => subject.Reviews.Count <= MaxReview);
            }
            return(this);
        }