/// <summary>
        /// Gets the level that will be associated to the SRS entry matching the
        /// given group in the current state.
        /// </summary>
        /// <returns>New level for the entity.</returns>
        private SrsLevel GetUpdatedLevel(SrsQuestionGroup group)
        {
            // Take the upper/lower level depending on the success state.
            int      modifier = group.IsWrong ? -1 : 1;
            SrsLevel newLevel = newLevel = SrsLevelStore.Instance.GetLevelByValue(
                group.Reference.CurrentGrade + modifier);

            // If the upper/lower level could not be obtained, (as this may
            // be the case when at max/min level), use the current one.
            // Note that this still may return a null value if the levels
            // were not loaded correctly or if the configuration has changed.
            return(newLevel ?? SrsLevelStore.Instance.GetLevelByValue(
                       group.Reference.CurrentGrade));
        }
        /// <summary>
        /// Processes the success/failure logic for the last answered question.
        /// Executed before getting to the next question.
        /// </summary>
        private void ProcessLastSubmission()
        {
            if (ReviewState == SrsReviewStateEnum.Success)
            {
                // Success. Set the question as answered.
                CurrentQuestion.IsAnswered = true;

                // If both questions of the group have been answered.
                if (!CurrentQuestionGroup.GetUnansweredQuestions().Any())
                {
                    SrsQuestionGroup group = CurrentQuestionGroup;

                    // Remove the group from the batch.
                    _currentBatch.Remove(group);

                    // Start the update group method after making sure the
                    // level store is finished loading.
                    SrsLevelStore.Instance.IssueWhenLoaded(
                        () => {
                        UpdateAnsweredGroup(group);
                    });

                    // Update the answered reviews count.
                    AnsweredReviewsCount++;

                    // Fill the batch to compensate for the removed group.
                    if (!IsWrappingUp)
                    {
                        FillCurrentBatch();
                    }
                    else if (_currentBatch.Count == 0)
                    {
                        StopSessionCommand.Execute(null);
                    }
                }
            }
            else if (ReviewState == SrsReviewStateEnum.Failure)
            {
                // Wrong answer.
                // Don't set the question as answered.
                // Set the group as wrong.
                CurrentQuestion.ParentGroup.IsWrong = true;
            }
        }
        /// <summary>
        /// Called to update the SRS entry referred by a question group that was
        /// answered.
        /// </summary>
        /// <param name="group">Question group answered.</param>
        private void UpdateAnsweredGroup(SrsQuestionGroup group)
        {
            // Get the new level of the item.
            SrsLevel newLevel = GetUpdatedLevel(group);

            // Update its grade and next answer date.
            if (newLevel != null)
            {
                // Set the next answer date according to the delay of the new level.
                if (newLevel.Delay.HasValue)
                {
                    group.Reference.NextAnswerDate =
                        DateTime.UtcNow
                        + newLevel.Delay.Value;
                }
                else
                {
                    group.Reference.NextAnswerDate = null;
                }

                group.Reference.CurrentGrade = newLevel.Value;
            }
            else
            {
                // If there is no new level and no current level, the delay is null.
                group.Reference.NextAnswerDate = null;
            }

            // Update the success/failure count.
            if (group.IsWrong)
            {
                group.Reference.FailureCount++;
            }
            else
            {
                group.Reference.SuccessCount++;
            }

            // Update the entry in the DB.
            UpdateEntry(group.Reference);
        }