Esempio n. 1
0
        public void AddStudent(Student student, CourseOffering offering)
        {
            // Check if the student already exists in the offering
            if (_studentRepository.StudentExists(offering, student.StudentNum))
                throw new StudentExistsException();

            // Insert the student into the offering
            _courseOfferingRepository.InsertStudentIntoCourseOffering(student, offering);
        }
        public void InsertStudentIntoCourseOffering(Student student, CourseOffering courseOffering)
        {
            // Get the current student from the offering
            var currentStudent = _dbContext.Students.FirstOrDefault(s => s.StudentNum == student.StudentNum);

            // Add / Register student
            courseOffering.Students.Add(currentStudent ?? student);

            // Persist to the DB
            Save();
        }
Esempio n. 3
0
        public static int CustomSort(Student a, Student b)
        {
            // If the students have different names, sort alphabetically
            if (a.Name.Equals(b.Name) == false) return a.CompareTo(b);

            // If the students have the same name
            if (a.Name.Equals(b.Name))
            {
                // If students have the same type
                return a.ToString().Equals(b.ToString())
                    // Sort by student number
                    ? string.Compare(a.StudentNum, b.StudentNum, StringComparison.Ordinal)
                    // Sort by student type
                    : GetStudentTypeValue(a.GetType()).CompareTo(GetStudentTypeValue(b.GetType()));
            }

            return -1;
        }
Esempio n. 4
0
 public void InsertStudent(Student student)
 {
     _dbContext.Students.Add(student);
 }
Esempio n. 5
0
 // Set default student sorting by name
 public int CompareTo(Student other) => other == null ? 1 : string.Compare(Name, other.Name, StringComparison.Ordinal);