private ChallengeView MapChallenge(ChallengeSpec spec, int sectionIndex = 0)
        {
            var section = spec.Challenge.Sections.ElementAtOrDefault(sectionIndex);

            var challenge = new ChallengeView
            {
                Text          = string.Join("\n\n", spec.Text, spec.Challenge.Text),
                LastScoreTime = spec.LastScoreTime,
                MaxPoints     = spec.MaxPoints,
                MaxAttempts   = spec.MaxAttempts,
                Attempts      = spec.Submissions.Count,
                Score         = Math.Round(spec.Score * spec.MaxPoints, 0, MidpointRounding.AwayFromZero),
                SectionIndex  = sectionIndex,
                SectionCount  = spec.Challenge.Sections.Count,
                SectionScore  = Math.Round(section.Score * spec.MaxPoints, 0, MidpointRounding.AwayFromZero),
                SectionText   = section.Text,
                Questions     = Mapper.Map <QuestionView[]>(section.Questions.Where(q => !q.Hidden))
            };

            foreach (var q in challenge.Questions)
            {
                q.Weight  = (float)Math.Round(q.Weight * spec.MaxPoints, 0, MidpointRounding.AwayFromZero);
                q.Penalty = (float)Math.Round(q.Penalty * spec.MaxPoints, 0, MidpointRounding.AwayFromZero);
            }

            return(challenge);
        }
Beispiel #2
0
        public ChallengeStanding(Challenge challenge)
        {
            Challenge = challenge;

            ChallengeView = new ChallengeView(this);
        }