Example #1
0
        private static bool IsTimerOut(CandidateExercise task, IList <CandidateExerciseResult> 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 CandidateTaskResult taskResult) ||
                taskResult.StartDate == null)
            {
                return(false);
            }

            return((DateTime.UtcNow - taskResult.StartDate.Value).TotalSeconds > task.TimeSeconds);
        }
Example #2
0
        private static int GetExerciseUsedTipsNumber(
            CandidateExercise exercise,
            IEnumerable <CandidateExerciseResult> candidateExerciseResults)
        {
            if (exercise.GetType() == typeof(CandidateTest))
            {
                return(TestUsedTipsNumber);
            }

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

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

            var taskResult = exerciseResult as CandidateTaskResult;

            return(taskResult?.UsedTipsNumber ?? TestUsedTipsNumber);
        }
Example #3
0
 private static ExerciseForList CreateExerciseForList(
     CandidateExercise exercise,
     IList <CandidateExerciseResult> 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.TimeSeconds.HasValue
     });
 }