コード例 #1
0
 private void FixGamePartRecordReference(ObjectivePart objective)
 {
     if (objective.Game == null)
     {
         var common = objective.As <CommonPart>();
         if (common != null && common.Container != null)
         {
             var game = _gameService.Value.Get(common.Container.Id);
             if (game != null)
             {
                 objective.Game = game.Record;
                 _repository.Update(objective.Record);
                 _repository.Flush();
             }
         }
     }
 }
        public void SubmitAnswer(ObjectivePart objective, TeamPart team, string answer)
        {
            Argument.ThrowIfNull(objective, "objective");
            Argument.ThrowIfNull(team, "team");
            Argument.ThrowIfNullOrEmpty(answer, "answer");

            var newSubmit = _actionSubmitService.NewActionSubmit <QuestionSubmitPart>(objective, team, "QuestionSubmit");

            newSubmit.Answer = answer.Trim();

            _contentManager.Create(newSubmit);

            var question = objective.As <QuestionObjectivePart>();

            if (question != null && question.AutoValidate)
            {
                var newActionSubmit = newSubmit.As <ActionSubmitPart>();

                var answers = question.Answers.ToList();
                if (answers.Any(a => a.Answer.Trim().ToLowerInvariant() == answer.Trim().ToLowerInvariant()))
                {
                    var resultPreset = objective.ObjectiveResultPresets.FirstOrDefault();

                    var points            = resultPreset.Points;
                    var resultDisplayName = resultPreset.DisplayName;

                    if (question.HintUsedByTeams.Any(teamHint => teamHint.TeamPartRecord.ContentItemRecord.Id == team.ContentItem.Id))
                    {
                        points -= question.HintPrice;
                    }

                    _actionSubmitService.Approve(newActionSubmit, resultDisplayName, points);
                }
                else
                {
                    _actionSubmitService.Reject(newActionSubmit);
                }
            }
        }