Пример #1
0
        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);
        }