Example #1
0
        public virtual async Task SetGradeAsync(int columnId, int userId, MoodleGradebookGrade grade)
        {
            // Sanity check
            if (grade.Score < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(grade.Score), "The score must not be negative.");
            }

            // Retrieve affected column
            var column = await GetColumnAsync(columnId);

            // Prepare score object
            var score = new MoodleLtiScore
            {
                UserId           = userId.ToString(),
                ScoreGiven       = grade.Score,
                Comment          = grade.Comment,
                Timestamp        = grade.Timestamp,
                ScoreMaximum     = column.MaximumScore,
                ActivityProgress = ActivityProgressStatus.Completed,
                GradingProgress  = GradingProgressStatus.FullyGraded
            };

            // Store score
            await _ltiApi.UpdateScoreAsync(columnId, score);
        }
Example #2
0
        public async Task UpdateScoreAsync(int lineItemId, MoodleLtiScore score)
        {
            // Build URL
            string url = $"{_serviceUrl}/lineitems/{lineItemId}/scores?{_queryStringPrefix}";

            // Serialize and send score
            string serializedScore = JsonConvert.SerializeObject(score, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            await DoPostRequestAsync(url, serializedScore, "application/vnd.ims.lis.v1.score+json", new[] { HttpStatusCode.OK });
        }
Example #3
0
        public Task UpdateScoreAsync(int lineItemId, MoodleLtiScore score)
        {
            if (!_lineItems.ContainsKey(lineItemId))
            {
                throw new MoodleLtiException(nameof(UpdateScoreAsync));
            }
            var lid = _lineItems[lineItemId];

            if (!lid.Scores.TryGetValue(score.UserId, out var s))
            {
                s = new MoodleLtiScore();
            }
            s.ActivityProgress = score.ActivityProgress;
            s.Comment          = score.Comment;
            s.GradingProgress  = score.GradingProgress;
            s.ScoreGiven       = score.ScoreGiven;
            s.ScoreMaximum     = score.ScoreMaximum;
            s.Timestamp        = score.Timestamp;

            return(Task.CompletedTask);
        }