private ScoreResult(User user, Exam exam, IEnumerable <Answer> answers, bool isBlocked, IEnumerable <string> tokens) { Username = user.Name; AnsweredQuestions = answers.Answered().Count(); CorrectQuestions = answers.Correct().Count(); Score = answers.Sum(answer => answer.ScoreAwarded ?? 0.0); var normalizedScore = ExamResult.NormalizeScore(Convert.ToDecimal(Score)); Excellence = normalizedScore > exam.MaximumScore; NormalizedScore = Math.Min(exam.MaximumScore, normalizedScore); Tokens = tokens.ToArray(); IsBlocked = isBlocked; }
public static object FromEntities(ExamResult exam, Question question, Answer answer, IIdentity user) { return(new QuestionResult { ExamId = exam.Id, Number = answer.Number, Type = question.Type, Text = question.Text, CanShowAnswer = exam.CanShowAnswer, IsBookmarked = answer.IsBookmarked, AnswerProvided = answer.AnswerProvided, AnswerText = exam.CanShowAnswer ? question.AnswerText : string.Empty, CorrectAnswer = exam.CanShowAnswer ? question.CorrectAnswer : string.Empty, QuestionData = question.GetQuestionData(GetRandomizationSeed(answer.Number, user.Name)) }); }