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(); }
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; }
public void InsertStudent(Student student) { _dbContext.Students.Add(student); }
// Set default student sorting by name public int CompareTo(Student other) => other == null ? 1 : string.Compare(Name, other.Name, StringComparison.Ordinal);