Exemple #1
0
 /// <summary>
 ///     Adds the student to a course offering.
 /// </summary>
 /// <param name="student">The student.</param>
 /// <param name="courseOfferingId">The course offering identifier.</param>
 public void AddStudentToCourseOffering(Student student, int courseOfferingId)
 {
     using (_courseOfferingRepository)
     {
         _courseOfferingRepository.InsertStudentIntoCourseOffering(student, courseOfferingId);
     }
 }
        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();
        }
 /// <summary>
 ///     Adds the student.
 /// </summary>
 /// <param name="student">The student.</param>
 public void InsertStudent(Student student)
 {
     using (var dbTransaction = _db.Database.BeginTransaction())
     {
         try
         {
             _db.Students.Add(student);
             _db.SaveChanges();
         }
         catch (Exception)
         {
             dbTransaction.Rollback();
         }
     }
 }
        public void InsertStudentIntoCourseOffering(Student student, int courseOfferingId)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                // If Course Offering exists
                var currentCourseOffering =
                    _db.CourseOfferings.SingleOrDefault(o => o.CourseOfferingId == courseOfferingId);
                if (currentCourseOffering == null)
                    throw new CourseOfferingDoesNotExistException();

                // If student exists
                var currentStudent = _db.Students.SingleOrDefault(s => s.StudentNumber == student.StudentNumber);

                if (currentStudent != null)
                {
                    if (currentCourseOffering.Students.Contains(currentStudent))
                        throw new StudentAlreadyInCourseOfferingException();
                }

                try
                {
                    if (currentStudent != null)
                        currentCourseOffering.Students.Add(currentStudent);
                    else
                    {
                        _db.Students.Add(student);
                        currentCourseOffering.Students.Add(student);
                    }
                    _db.SaveChanges();
                    dbTransaction.Commit();
                }
                catch (Exception)
                {
                    // If student does not exist create student
                    dbTransaction.Rollback();
                }
                ;
            }
        }
Exemple #5
0
 // Set default student sorting by name
 public int CompareTo(Student other) => other == null ? 1 : string.Compare(Name, other.Name, StringComparison.Ordinal);
Exemple #6
0
 public void InsertStudent(Student student)
 {
     _dbContext.Students.Add(student);
 }
Exemple #7
0
        /// <summary>
        ///     Adds the student.
        /// </summary>
        /// <param name="student">The student.</param>
        /// <exception cref="StudentExistsException"></exception>
        public void AddStudent(Student student)
        {
            using (_studentRepository)
            {
                if (_studentRepository.HasStudent(student))
                    throw new StudentExistsException();

                _studentRepository.InsertStudent(student);
            }
        }
 /// <summary>
 ///     Determines whether the specified student already exists.
 /// </summary>
 /// <param name="student">The student.</param>
 /// <returns></returns>
 public bool HasStudent(Student student) => _db.Students.Any(s => s.StudentNumber == student.StudentNumber);