コード例 #1
0
        // Load students
        private static List <DataTableStudent> GetStudents(int courseId, string accessToken)
        {
            var config        = SystemConfig.LoadConfig();
            var dataAccess    = new CanvasDataAccess(config);
            var students      = dataAccess.GetUsersInCourse(accessToken, courseId, EnrollmentParamType.student);
            var tableStudents = new List <DataTableStudent>();

            foreach (var student in students)
            {
                var tbStudent = new DataTableStudent
                {
                    Name          = student.Name,
                    Id            = student.Id,
                    InstitutionId = student.SisUserId
                };
                tableStudents.Add(tbStudent);
            }
            return(tableStudents);
        }
コード例 #2
0
        public IActionResult GetCourseStudents([FromRoute] int courseId, [FromQuery] int pageNumber = -1)
        {
            var userToken = _tokenManager.ReadAndValidateToken(Request.Headers[_config.authHeader]);

            JwtSecurityToken decodedToken;
            var handler      = new JwtSecurityTokenHandler();
            var listResponse = new ListResponse <User>();

            try
            {
                decodedToken = handler.ReadJwtToken(userToken);
            }
            catch (ArgumentException)
            {
                listResponse.ResponseMessage = "User Token Is Not Valid";
                return(new UnauthorizedObjectResult(listResponse));
            }

            var sysUserId = _tokenManager.GetUserIdFromToken(decodedToken);

            var canvasPat = _canvasTokenManager.GetActiveAccessToken(sysUserId);

            if (canvasPat == null)
            {
                listResponse.ResponseMessage = "No Canvas PAT Selected/Activated!";
                return(new BadRequestObjectResult(listResponse));
            }

            try
            {
                listResponse.ListContent = _canvasDataAccess.GetUsersInCourse(canvasPat, courseId,
                                                                              EnrollmentParamType.student, pageNumber);
                listResponse.ResponseMessage = "Successful retreival of Canvas Students";
                return(Ok(listResponse));
            }
            catch (Exception)
            {
                listResponse.ResponseMessage = "Failed to retreive students from Canvas";
                return(new BadRequestObjectResult(listResponse));
            }
        }