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) ) )); }
public async Task <Course> GetCourseAsync(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); } return(new Course( id: FromBson.GetId(document), version: FromBson.GetVersion(document), title: FromBson.GetCourseTitle(document), teacher: FromBson.GetCourseTeacher(document), capacity: FromBson.GetCourseCapacity(document) )); }
public async Task <Student> GetStudentAsync(string email) { Guard.NotNullOrEmpty(email, nameof(email)); var filter = Builders <BsonDocument> .Filter .Eq(Fields.StudentEmail, email); var document = await _context.Students .Find(filter) .SingleOrDefaultAsync(); if (document == null) { return(null); } return(new Student( id: FromBson.GetId(document), version: FromBson.GetVersion(document), email: FromBson.GetStudentEmail(document), name: FromBson.GetStudentName(document), age: FromBson.GetStudentAge(document) )); }