Esempio n. 1
0
        public void Cancel(Course course)
        {
            if (null == course)
            {
                throw new ArgumentNullException(nameof(course));
            }

            var oldCourses = _courses.Where(c => c.CourseId == course.Id).ToArray();

            var isEmpty = !oldCourses.Any();

            var isCompleted = !isEmpty && oldCourses.OrderByDescending(c => c.CreatedAt).First().Status == StudentCourseStatus.Statuses.Completed;

            if (isCompleted)
            {
                throw new ArgumentException($"student {this.Id} has completed course {course.Id} already");
            }

            var isEnrolled = !isEmpty && oldCourses.OrderByDescending(c => c.CreatedAt).First().Status == StudentCourseStatus.Statuses.Enrolled;

            if (!isEnrolled)
            {
                throw new ArgumentException($"student {this.Id} not enrolled in course {course.Id}");
            }

            _courses.Add(StudentCourseStatus.Withdrawn(this, course));
            AddEvent(new StudentWithdrawn(this, course));
        }
Esempio n. 2
0
        public void Add(Course course)
        {
            if (null == course)
            {
                throw new ArgumentNullException(nameof(course));
            }

            var oldCourses = _courses.Where(c => c.CourseId == course.Id).ToArray();

            var isEmpty      = !oldCourses.Any();
            var hasWithdrawn = !isEmpty && oldCourses.OrderByDescending(c => c.CreatedAt).First().Status == StudentCourseStatus.Statuses.Withdrawn;

            if (isEmpty || hasWithdrawn)
            {
                _courses.Add(StudentCourseStatus.Enrolled(this, course));
                AddEvent(new StudentEnrolled(this, course));
            }
        }
Esempio n. 3
0
        public void Complete(Course course)
        {
            if (null == course)
            {
                throw new ArgumentNullException(nameof(course));
            }

            var oldCourses = _courses.Where(c => c.CourseId == course.Id).ToArray();

            if (!oldCourses.Any())
            {
                throw new ArgumentException($"Student {Id} not enrolled in course {course.Id}");
            }
            if (oldCourses.Any(c => c.Status == StudentCourseStatus.Statuses.Withdrawn))
            {
                throw new ArgumentException($"Student {Id} has withdrawn from course {course.Id}");
            }

            _courses.Add(StudentCourseStatus.Completed(this, course));
            AddEvent(new CourseCompleted(this, course));
        }