示例#1
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));
        }
示例#2
0
        private static List <CourseDataColumn> GetAssignmentColumns(int courseId, string accessToken)
        {
            var assignmentCols = new List <CourseDataColumn>();
            var config         = SystemConfig.LoadConfig();
            var dataAccess     = new CanvasDataAccess(config);
            var assignments    = dataAccess.GetCourseAssignments(accessToken, courseId);

            foreach (var assignment in assignments)
            {
                var col = new NumericDataColumn
                {
                    Name          = assignment.Name,
                    RelatedDataId = assignment.Id,
                    ColumnId      = Guid.NewGuid(),
                    ColumnType    = ColumnType.Assignment_Score,
                    DataType      = ColumnDataType.Number,
                    ColMaxValue   = assignment.PointsPossible,
                    ColMinValue   = 0,
                    Rows          = new List <NumericDataRow>()
                };
                assignmentCols.Add(col);
            }
            return(assignmentCols);
        }