public async Task <ActionResult <CourseRolesResponse> > CourseRoles() { var userId = User.GetUserId(); var isSystemAdministrator = User.IsSystemAdministrator(); var visibleCourses = unitsRepo.GetVisibleCourses(); var rolesByCourse = (await courseRolesRepo.GetRolesAsync(userId).ConfigureAwait(false)) .Where(kvp => kvp.Value != CourseRoleType.Student).ToList(); var courseAccesses = await coursesRepo.GetUserAccessesAsync(userId).ConfigureAwait(false); var courseAccessesByCourseId = courseAccesses.GroupBy(a => a.CourseId).Select( g => new CourseAccessResponse { CourseId = g.Key, Accesses = g.Select(a => a.AccessType).ToList() } ).ToList(); var coursesInWhichUserHasAnyRole = new HashSet <string>(rolesByCourse.Select(kvp => kvp.Key), StringComparer.OrdinalIgnoreCase); var groupsWhereIAmStudent = (await groupMembersRepo.GetUserGroupsAsync(userId).ConfigureAwait(false)) .Where(g => visibleCourses.Contains(g.CourseId) || coursesInWhichUserHasAnyRole.Contains(g.CourseId)); return(new CourseRolesResponse { IsSystemAdministrator = isSystemAdministrator, CourseRoles = rolesByCourse.Select(kvp => new CourseRoleResponse { CourseId = kvp.Key, Role = kvp.Value, }).ToList(), CourseAccesses = courseAccessesByCourseId, GroupsAsStudent = groupsWhereIAmStudent.Where(g => g.CanUsersSeeGroupProgress).Select(BuildShortGroupInfo).ToList() }); }
public async Task <ActionResult <CourseRolesResponse> > CourseRoles() { var userId = User.GetUserId(); var isSystemAdministrator = User.IsSystemAdministrator(); var rolesByCourse = await courseRolesRepo.GetRolesAsync(userId).ConfigureAwait(false); var courseAccesses = await coursesRepo.GetUserAccessesAsync(userId).ConfigureAwait(false); var courseAccessesByCourseId = courseAccesses.GroupBy(a => a.CourseId).Select( g => new CourseAccessResponse { CourseId = g.Key, Accesses = g.Select(a => a.AccessType).ToList() } ).ToList(); return(new CourseRolesResponse { IsSystemAdministrator = isSystemAdministrator, Roles = rolesByCourse.Where(kvp => kvp.Value != CourseRoleType.Student).Select(kvp => new CourseRoleResponse { CourseId = kvp.Key, Role = kvp.Value, }).ToList(), Accesses = courseAccessesByCourseId, }); }
public async Task <ActionResult <CourseRolesResponse> > CourseRoles() { var userId = User.GetUserId(); var isSystemAdministrator = User.IsSystemAdministrator(); var rolesByCourse = await courseRolesRepo.GetRolesAsync(userId).ConfigureAwait(false); var courseAccesses = await coursesRepo.GetUserAccessesAsync(userId).ConfigureAwait(false); var courseAccessesByCourseId = courseAccesses.GroupBy(a => a.CourseId).Select( g => new CourseAccessResponse { CourseId = g.Key, Accesses = g.Select(a => a.AccessType).ToList() } ).ToList(); var groupsWhereIAmStudent = await groupMembersRepo.GetUserGroupsAsync(userId).ConfigureAwait(false); return(new CourseRolesResponse { IsSystemAdministrator = isSystemAdministrator, CourseRoles = rolesByCourse.Where(kvp => kvp.Value != CourseRoleType.Student).Select(kvp => new CourseRoleResponse { CourseId = kvp.Key, Role = kvp.Value, }).ToList(), CourseAccesses = courseAccessesByCourseId, GroupsAsStudent = groupsWhereIAmStudent.Where(g => g.CanUsersSeeGroupProgress).Select(BuildShortGroupInfo).ToList() }); }