Inheritance: LtiLibrary.Core.Common.BasicResult
Esempio n. 1
0
 /// <summary>
 /// Delete the score from the consumer database.
 /// </summary>
 /// <param name="lisResultSourcedId">The SourcedId of the score to delete.</param>
 /// <returns>True if the score is deleted.</returns>
 protected override bool DeleteResult(string lisResultSourcedId)
 {
     // Only valid SourcedId values are "1", "2", and "3" (see Lti1Controller)
     if (lisResultSourcedId.Equals("1") || lisResultSourcedId.Equals("2") || lisResultSourcedId.Equals("3"))
     {
         _lisResult = null;
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /// <summary>
 /// Store the score in the consumer database.
 /// </summary>
 /// <param name="result">The LisResult to store.</param>
 /// <returns>True if the score is saved.</returns>
 protected override bool ReplaceResult(LisResult result)
 {
     if (_lisResult == null)
     {
         _lisResult = new LisResult();
     }
     _lisResult.IsValid = true;
     _lisResult.Score = result.Score;
     _lisResult.SourcedId = result.SourcedId;
     return true;
 }
Esempio n. 3
0
 /// <summary>
 /// Store the score in the consumer database.
 /// </summary>
 /// <param name="result">The LisResult to store.</param>
 /// <returns>True if the score is saved.</returns>
 protected override bool ReplaceResult(LisResult result)
 {
     // Only valid SourcedId values are "1", "2", and "3" (see Lti1Controller)
     if (result.SourcedId.Equals("1") || result.SourcedId.Equals("2") || result.SourcedId.Equals("3"))
     {
         if (_lisResult == null)
         {
             _lisResult = new LisResult();
         }
         _lisResult.IsValid = true;
         _lisResult.Score = result.Score;
         _lisResult.SourcedId = result.SourcedId;
         return true;
     }
     return false;
 }
Esempio n. 4
0
 /// <summary>
 /// Delete the score from the consumer database.
 /// </summary>
 /// <param name="lisResultSourcedId">The SourcedId of the score to delete.</param>
 /// <returns>True if the score is deleted.</returns>
 protected override bool DeleteResult(string lisResultSourcedId)
 {
     _lisResult = null;
     return true;
 }
 /// <summary>
 /// Save or update the result (grade, score, outcome) in the consumer.
 /// </summary>
 /// <param name="result">The result to save or update.</param>
 /// <returns>True if the result was saved or updated.</returns>
 protected abstract bool ReplaceResult(LisResult result);
 /// <summary>
 /// Convert the ResultRecordType into the Result type.
 /// </summary>
 /// <param name="resultRecord">The ResultRecordType which 
 /// specifies the assignment and score.</param>
 /// <returns>The corresponding Result</returns>
 private static LisResult GetResult(ResultRecordType resultRecord)
 {
     var result = new LisResult { SourcedId = resultRecord.sourcedGUID.sourcedId };
     if (resultRecord.result != null)
     {
         // The LTI 1.1 specification states in 6.1.1. that the score in replaceResult should
         // always be formatted using “en” formatting
         // (http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html#_Toc330273034).
         const NumberStyles style = NumberStyles.Number | NumberStyles.AllowDecimalPoint;
         var culture = CultureInfo.CreateSpecificCulture(LtiConstants.ScoreLanguage);
         double value;
         if (double.TryParse(resultRecord.result.resultScore.textString, style, culture, out value))
         {
             if (value >= 0 && value <= 1)
             {
                 result.Score = value;
             }
         }
     }
     return result;
 }
Esempio n. 7
0
 /// <summary>
 /// Fill the Result with corresponding Score data.
 /// </summary>
 /// <param name="lisResultSourcedId">The sourcedId of the LisResult to read.</param>
 /// <returns>True if the Score was found and the Result is valid.</returns>
 protected override LisResult ReadResult(string lisResultSourcedId)
 {
     var score = GetScore(lisResultSourcedId);
     var result = new LisResult();
     if (score.IsValid)
     {
         result.IsValid = true;
         result.Score = score.Score == null ? default(double?) : score.Score.DoubleValue;
         result.SourcedId = lisResultSourcedId;
     }
     else
     {
         result.IsValid = false;
     }
     return result;
 }
Esempio n. 8
0
 /// <summary>
 /// Create a new Score based on the Result that was sent.
 /// </summary>
 /// <param name="result">The result record that was sent in the request.</param>
 /// <returns>The Score based on the result.</returns>
 private static Score CreateScore(LisResult result)
 {
     var sourcedId = JsonConvert.DeserializeObject<LisResultSourcedId>(result.SourcedId);
     return new Score
         {
             AssignmentId = sourcedId.AssignmentId,
             UserId = sourcedId.UserId
         };
 }
Esempio n. 9
0
 /// <summary>
 /// Create or update a Score with the LTI result.
 /// </summary>
 /// <param name="result">The LTI result.</param>
 /// <returns>True if the Score was created or updated.</returns>
 protected override bool ReplaceResult(LisResult result)
 {
     var score = GetScore(result.SourcedId);
     if (score.IsValid)
     {
         if (score.Score == null)
         {
             score.Score = CreateScore(result);
             ConsumerContext.Scores.Add(score.Score);
         }
         if (result.Score.HasValue)
         {
             score.Score.DoubleValue = result.Score.Value;
         }
         ConsumerContext.SaveChanges();
         return true;
     }
     return false;
 }