Ejemplo n.º 1
0
        public IActionResult GetCourseDataTable([FromRoute] int courseId)
        {
            var userToken = _tokenManager.ReadAndValidateToken(Request.Headers[_config.authHeader]);

            JwtSecurityToken decodedToken;
            var handler     = new JwtSecurityTokenHandler();
            var objResponse = new ObjectResponse <CourseDataTable>();

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

            var sysUserId = _tokenManager.GetUserIdFromToken(decodedToken);

            var canvasPat = _canvasTokenManager.GetActiveAccessToken(sysUserId);

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

            var dataTable = CourseDataTable.LoadDataTable(courseId, canvasPat, _dbCtx);

            objResponse.Value   = dataTable;
            objResponse.Message = "Successful retrevial of data table";

            return(Ok(objResponse));
        }
        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));
            }
        }
Ejemplo n.º 3
0
        public IActionResult GetCourseAssignments([FromRoute] int courseId)
        {
            var userToken = _tokenManager.ReadAndValidateToken(Request.Headers[_config.authHeader]);

            JwtSecurityToken decodedToken;
            var handler     = new JwtSecurityTokenHandler();
            var objResponse = new ListResponse <Assignment>();

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

            var sysUserId = _tokenManager.GetUserIdFromToken(decodedToken);

            var canvasPat = _canvasTokenManager.GetActiveAccessToken(sysUserId);

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

            try
            {
                objResponse.ListContent = _canvasDataAccess.GetCourseAssignments(canvasPat, courseId);
            }
            catch (Exception)
            {
                objResponse.ResponseMessage = "Error occured during retrevial of canvas courses";
                return(new NotFoundObjectResult(objResponse));
            }

            return(new OkObjectResult(objResponse));
        }