Example #1
0
        public void start()
        {
            List <Student> students = new List <Student>();

            var getFacultyNames = (from faculty in context.Faculties
                                   select faculty.FacultyName).Distinct();

            List <String> facultyNames = getFacultyNames.ToList();
            List <String> studentEGNs;

            //if we try to rate for a second time we should clear the rejected students and
            //those who did not enroll

            var entriesToDelete = from student in context.Students
                                  from entry in context.FacultyRankLists
                                  where entry.EGN == student.EGN
                                  where student.IsEnrolled == false || (entry.ProgrammeName.StartsWith(CONST_REJECTED + " "))
                                  select entry;

            foreach (FacultyRankList entry in entriesToDelete)
            {
                context.FacultyRankLists.Attach(entry);
                context.FacultyRankLists.Remove(entry);
            }
            context.SaveChanges();

            //iterate through every faculty
            foreach (String facultyName in facultyNames)
            {
                var getStudentsEGNQuery = (from student in context.Students
                                           from preference in context.Preferences
                                           from faculty in context.Faculties
                                           where student.IsEnrolled == false
                                           where faculty.FacultyName == facultyName &&
                                           preference.ProgrammeName == faculty.ProgrammeName &&
                                           preference.EGN == student.EGN
                                           select student.EGN).Distinct();

                var getApprovedStudentsEGNQuery = (from entry in context.FacultyRankLists
                                                   from faculty in context.Faculties
                                                   where faculty.FacultyName == facultyName
                                                   where entry.ProgrammeName == faculty.ProgrammeName || (entry.ProgrammeName.Equals(CONST_REJECTED + " " + faculty.FacultyName))
                                                   select entry.EGN).Distinct();

                int count;
                studentEGNs = getStudentsEGNQuery.ToList();

                //this while cycle is used to match any remaining students rejected
                //in previous iterations
                do
                {
                    count = 0;
                    //iterate through every student with a preference in this faculty
                    foreach (String EGN in studentEGNs)
                    {
                        Student student;
                        student = queryManager.getStudent(EGN);

                        //TODO: This row is for debugging only
                        List <String> lst = getApprovedStudentsEGNQuery.ToList();

                        //if the student is already approved for a programme, skip him/her
                        if (!getApprovedStudentsEGNQuery.Contains(EGN))
                        {
                            serve(facultyName, student);
                            count++;
                        }
                    }
                }while (count > 0);
            }
        }