Exemple #1
0
        private static bool IsTimerOut(Exercise task, IList <ExerciseResult> candidateExerciseResults)
        {
            if (task == null || candidateExerciseResults == null)
            {
                return(false);
            }

            var result = candidateExerciseResults.FirstOrDefault(res => res.CandidateExerciseId == task.Id);

            if (result == null || result.Score != 0 || !(result is TaskResult taskResult) ||
                taskResult.StartDate == null)
            {
                return(false);
            }

            return((DateTime.UtcNow - taskResult.StartDate.Value).TotalSeconds > task.TimeMinutes * 60);
        }
Exemple #2
0
        private static int GetExerciseUsedTipsNumber(
            Exercise exercise,
            IEnumerable <ExerciseResult> candidateExerciseResults)
        {
            if (exercise.GetType() == typeof(TestModel))
            {
                return(TestUsedTipsNumber);
            }

            var exerciseResult = candidateExerciseResults.FirstOrDefault(
                result => result.CandidateExerciseId == exercise.Id);

            if (exerciseResult == null)
            {
                return(TestUsedTipsNumber);
            }

            var taskResult = exerciseResult as TaskResult;

            return(taskResult?.UsedTipsNumber ?? TestUsedTipsNumber);
        }
Exemple #3
0
 private static ExerciseForList CreateExerciseForList(
     Exercise exercise,
     IList <ExerciseResult> candidateExerciseResults)
 {
     return(new ExerciseForList
     {
         Id = exercise.Id,
         Name = exercise.Name,
         Subject = exercise.Subject,
         MaximumScore = exercise.MaximumScore,
         CandidateScore = candidateExerciseResults.FirstOrDefault(
             result => result.CandidateExerciseId == exercise.Id)?.Score ?? ExerciseNotCompleted,
         UsedTipsNumber = GetExerciseUsedTipsNumber(exercise, candidateExerciseResults),
         IsCompleted = candidateExerciseResults.Any(result => result.CandidateExerciseId == exercise.Id && result.Score != 0),
         ResultId = candidateExerciseResults.FirstOrDefault(
             result => result.CandidateExerciseId == exercise.Id)?.Id ?? ExerciseNotCompleted,
         IsSoftDeleted = false,
         IsTimeOut = IsTimerOut(exercise, candidateExerciseResults),
         HasTimer = exercise.TimeMinutes.HasValue
     });
 }