예제 #1
0
        private static CourseRM MapCourseRM(CourseDM course)
        {
            if (course is null)
            {
                throw new ArgumentNullException(nameof(course));
            }

            var courseRM = new CourseRM
            {
                CourseId       = course.Id,
                Title          = course.Title,
                StarttDateTime = course.DateTimeRange.Start,
                EndDateTime    = course.DateTimeRange.End,
                MaxCapacity    = course.MaxCapacity.MaxOccupant,
                Students       = course.Students.Select(s =>
                                                        new StudentRM
                {
                    StudentId = s.Id,
                    FirstName = s.FirstName,
                    LastName  = s.LastName,
                })
            };

            return(courseRM);
        }
        public void AddStudent()
        {
            var numberOfDays = DateTimeRange.CreateOneWeekRange(DateTime.Now);
            var maxCapacity  = new Capacity(20);
            var instructorId = Guid.NewGuid();
            var students     = Enumerable.Empty <StudentDM>();
            var course       = CourseDM.CreateCourse("Computer", numberOfDays, maxCapacity, instructorId, students);

            course.AddStudent(new StudentDM(Guid.NewGuid(), "John", "Adam"));

            course.Students.Count.Should().BeGreaterThan(0);
        }
        public void CreateCourse()
        {
            var numberOfDays = DateTimeRange.CreateOneWeekRange(DateTime.Now);
            var maxCapacity  = new Capacity(20);
            var instructorId = Guid.NewGuid();
            var students     = new[]
            {
                new StudentDM(Guid.NewGuid(), "John", "Adam"),
                new StudentDM(Guid.NewGuid(), "Marry", "Smith")
            };
            var course = CourseDM.CreateCourse("Computer", numberOfDays, maxCapacity, instructorId, students);

            course.Should().NotBeNull();
        }
        public async Task <CourseDM> GetByIdAsync(Guid courseId)
        {
            var course = await _context.Courses.FirstOrDefaultAsync(c => c.Id == courseId);

            var students = _context.CourseEnrollments
                           .Where(ce => ce.CourseId == courseId)
                           .Select(ce => ce.Student);

            var instructor = _context.CourseAssignments
                             .Where(ca => ca.CourseId == courseId)
                             .Select(ca => ca.Instructor).First();

            var courseDM = new CourseDM(
                id: courseId,
                title: course.Title,
                dateTimeRange: new DateTimeRange(course.StartDateTime, course.EndDateTime),
                maxCapacity: new Capacity(course.MaxCapacity),
                instructorId: instructor.Id,
                students: students.Select(s => new StudentDM(s.Id, s.FirstName, s.LastName))
                );

            return(courseDM);
        }
 public Task AddCourse(CourseDM course)
 {
     throw new NotImplementedException();
 }