Esempio n. 1
0
        public void Update(Offering offering)
        {
            if (offering == null)
            {
                throw new ArgumentNullException("offering");
            }

            SetOfferingProperties(offering);

            ValidateOffering(offering);

            offering.Enrollments = (ICollection <Enrollment>)EnrollmentService
                                   .GetEnrollmentsByOfferingId(offering.Id);

            offering.Schedules = (ICollection <Schedule>)ScheduleService
                                 .FindByOfferingId(offering.Id);

            _offeringRepository.Update(offering);
        }
Esempio n. 2
0
        public void Remove(Offering offering, bool forceToRemove)
        {
            if (offering.Enrollments.Count > 0 && !offering.Term.IsCurrentTerm)
            {
                throw new ForeignKeyEntityException("The offering could not be removed because it has students enrolled in it, and it was offered in another term.");
            }

            if (offering.Enrollments.Count > 0 && offering.Term.IsCurrentTerm && !forceToRemove)
            {
                throw new ForeignKeyEntityException("The offering could not be removed because it has students enrolled in it, and it was offered in another term.");
            }

            // Send an email to students currently enrolled in the offering that this will be removed
            var emailMessage = new EmailMesageService();

            foreach (var enrollment in offering.Enrollments)
            {
                var student = StudentService.Get(enrollment.StudentId);

                string subject = "Offering removed!!!";
                string body    = $"{student.LastName}, {student.FirstName},\n" +
                                 $"{offering.Title} is not longer available.\n" +
                                 "You might want to enroll in a new one if you wish." +
                                 "Sorry for any incoveninence that this causes you.";

                emailMessage.Sent(student.Email, subject, body);
            }

            // Remove enrollment and evaluations
            EnrollmentService.RemoveRange(offering.Enrollments);

            // Remove schedules for the offering
            ScheduleService.RemoveRange(offering.Schedules);

            // Remove offering
            _offeringRepository.Remove(offering);
        }