private GetUserResultsResponse UserResults(User usr) { //Load modules var coachingCourseRepository = new CoachingCourseRepositoryDocumentDB(); var coachingModuleRepository = new CoachingModuleRepositoryDocumentDB(); var moduleGroupRepository = new ModuleGroupRepositoryDocumentDB(); //TODO: Support multiple course admissions var course = coachingCourseRepository.GetCourseById(usr.CourseAdmissions.Single().CourseId); var modules = coachingModuleRepository.GetModulesWithIds(course.Modules.Select(m => m.ModuleReferenceId)).ToList(); var moduleGroups = moduleGroupRepository.GetItemsWithIds(course.ModuleGroups); var userResults = new GetUserResultsResponse() { ModuleResults = modules.Select(m => { var moduleResults = usr.CourseAdmissions.Single().Results.Where(r => r.Module.ModuleReferenceId == m.Id ).ToList(); return(new ModuleResultsDto() { Module = CoachingModuleDTOConverter.ConvertToDTO(m), ModuleResults = moduleResults.Select(mr => UserDtoConverter.ConvertScoreCardDto(mr)).ToList() }); }).ToList(), Groups = moduleGroups.Select(CoachingModuleDTOConverter.ConvertToDTO), User = UserDtoConverter.ConvertUserToBaseDto(usr) }; userResults.ActiveModule = userResults.ModuleResults.FirstOrDefault(mr => mr.ModuleResults.Any(r => !r.IsCompleted)).Module; userResults.ActiveModuleIndex = modules.IndexOf(modules.Single(m => m.Id == userResults.ActiveModule.Id)); return(userResults); }
public IEnumerable <CoachingModuleDTO> Modules(Guid courseId) { var coachingCourseRepository = new CoachingCourseRepositoryDocumentDB(); var coachingModuleRepository = new CoachingModuleRepositoryDocumentDB(); //Get the course var course = coachingCourseRepository.GetCourseById(courseId); //Get modules in course var modules = coachingModuleRepository.GetItemsWithIds(course.Modules.Select(m => m.ModuleReferenceId)).OrderBy(m => m.ModuleIndex); return(modules.Select(m => CoachingModuleDTOConverter.ConvertToDTO(m))); }
public Guid Post(CreateModuleInCourseRequest request) { var coachingCourseRepository = new CoachingCourseRepositoryDocumentDB(); var coachingModuleResourceRepository = new ModuleResourceRepositoryDocumentDb(); var coachingModuleRepository = new CoachingModuleRepositoryDocumentDB(); var exerciseRepository = new CoachnigModuleExerciseResourceRepositoryDocumentDB(); var userRepository = new UserRepositoryDocumentDB(); var coachingService = new CoachingCourseService( coachingCourseRepository, coachingModuleResourceRepository, coachingModuleRepository, exerciseRepository, userRepository); var course = coachingCourseRepository.GetCourseById(request.CourseId); var module = coachingService.CreateNewModuleInCourse(course, request.ModuleName, 0); return(course.Id); }