private int GetMaxSlideScoreForUser(Course course, Slide slide, string userId) { var solvedSlidesIds = ControllerUtils.GetSolvedSlides(solutionsRepo, userQuizzesRepo, course, userId); var slidesWithUsersManualChecking = new HashSet <Guid>(visitsRepo.GetSlidesWithUsersManualChecking(course.Id, userId)); var enabledManualCheckingForUser = groupsRepo.IsManualCheckingEnabledForUser(course, userId); var maxSlideScore = ControllerUtils.GetMaxScoreForUsersSlide(slide, solvedSlidesIds.Contains(slide.Id), slidesWithUsersManualChecking.Contains(slide.Id), enabledManualCheckingForUser); return(maxSlideScore); }
private TocModel CreateTocModel(Course course, Guid?currentSlideId, string userId) { var visibleUnits = unitsRepo.GetVisibleUnits(course, User); var visited = visitsRepo.GetIdOfVisitedSlides(course.Id, userId); var scoresForSlides = visitsRepo.GetScoresForSlides(course.Id, userId); var solvedSlidesIds = ControllerUtils.GetSolvedSlides(solutionsRepo, userQuizzesRepo, course, userId); var slidesWithUsersManualChecking = visitsRepo.GetSlidesWithUsersManualChecking(course.Id, userId).ToImmutableHashSet(); var enabledManualCheckingForUser = groupsRepo.IsManualCheckingEnabledForUser(course, userId); Func <Slide, int> getSlideMaxScoreFunc = s => ControllerUtils.GetMaxScoreForUsersSlide(s, solvedSlidesIds.Contains(s.Id), slidesWithUsersManualChecking.Contains(s.Id), enabledManualCheckingForUser); var userGroupsIds = groupsRepo.GetUserGroupsIds(course.Id, userId); var enabledScoringGroupsIds = groupsRepo.GetEnabledAdditionalScoringGroups(course.Id) .Where(e => userGroupsIds.Contains(e.GroupId)) .Select(e => e.ScoringGroupId) .ToList(); var additionalScores = additionalScoresRepo.GetAdditionalScoresForUser(course.Id, userId); var builder = new TocModelBuilder( s => Url.RouteUrl("Course.SlideById", new { courseId = course.Id, slideId = s.Url }), s => scoresForSlides.ContainsKey(s.Id) ? scoresForSlides[s.Id] : 0, getSlideMaxScoreFunc, (u, g) => additionalScores.GetOrDefault(Tuple.Create(u.Id, g.Id), 0), course, currentSlideId) { GetUnitInstructionNotesUrl = unit => Url.Action("InstructorNote", "Course", new { courseId = course.Id, unitId = unit.Id }), GetUnitStatisticsUrl = unit => Url.Action("UnitStatistics", "Analytics", new { courseId = course.Id, unitId = unit.Id }), IsInstructor = User.HasAccessFor(course.Id, CourseRole.Instructor), IsSolved = s => solvedSlidesIds.Contains(s.Id), IsVisited = s => visited.Contains(s.Id), IsUnitVisible = visibleUnits.Contains, IsSlideHidden = s => s is QuizSlide && ((QuizSlide)s).ManualChecking && !enabledManualCheckingForUser && !solvedSlidesIds.Contains(s.Id), EnabledScoringGroupsIds = enabledScoringGroupsIds, }; var userGroups = groupsRepo.GetUserGroups(course.Id, User.Identity.GetUserId()); var tocGroupsForStatistics = userGroups.Select(g => new TocGroupForStatistics { GroupName = g.Name, StatisticsUrl = Url.Action("CourseStatistics", "Analytics", new { courseId = course.Id, group = g.Id }) }); var toc = builder.CreateTocModel(tocGroupsForStatistics.ToList()); toc.NextUnitTime = unitsRepo.GetNextUnitPublishTime(course.Id); return(toc); }