Ejemplo n.º 1
0
        public async Task <CourseEnrollment> GetCourseEnrollmentAsync(string courseTitle)
        {
            Guard.NotNullOrEmpty(courseTitle, nameof(courseTitle));

            var filter = Builders <BsonDocument> .Filter
                         .Eq(Fields.CourseTitle, courseTitle);

            var document = await _context.Courses
                           .Find(filter)
                           .SingleOrDefaultAsync();

            if (document == null)
            {
                return(null);
            }

            BsonDocument summaryDoc = FromBson.GetSummaryDocument(document);

            return(new CourseEnrollment(
                       courseId:       FromBson.GetId(document),
                       courseVersion:  FromBson.GetVersion(document),
                       courseTitle:    FromBson.GetCourseTitle(document),
                       capacity:       FromBson.GetCourseCapacity(document),
                       students:       FromBson.GetCourseStudents(document),
                       summary:        new CourseSummary(
                           ageMin:         FromBson.GetSummaryMin(summaryDoc),
                           ageMax:         FromBson.GetSummaryMax(summaryDoc),
                           ageSum:         FromBson.GetSummarySum(summaryDoc),
                           ageAvg:         FromBson.GetSummaryAvg(summaryDoc),
                           studentCount:   FromBson.GetSummaryStudentCount(summaryDoc)
                           )
                       ));
        }