Beispiel #1
0
        public override void Handle(Entity.Command command, IOutput output)
        {
            CheckSurveyIdIsGiven(command);

            var id     = OptionParser.ParseOption("i", command)[0];
            var survey = _repository.FindOne(id);

            CheckSurveyIsStillActive(survey);

            if (OptionParser.HasOption("s", command))
            {
                output.WriteLineForUser("---------------------------------------------");
                output.WriteLineForUser($"The available choices for the question \"{survey.Question.Value}\" :");
                survey.Choices.ForEach(currentChoice => output.WriteLineForUser($"\t- {currentChoice.Value}"));
                output.WriteLineForUser("");
                return;
            }

            CheckChoiceHasBeenGiven(command);

            var choice = survey.Choices
                         .Find(currentChoice => currentChoice.Value == OptionParser.ParseOption("c", command)[0]);

            CheckChoiceIsNotNull(choice);
            CheckPlayerHasNotVotedYet(survey);

            survey.Votes.Add(new Domain.Entity.Vote(_player.Id, choice));

            var request = _facade.ToSaveSurveyFactory().CreateRequest(survey);

            _facade.ToSaveSurveyFactory()
            .CreateExecutor(_repository)
            .Execute(request, new EmptyStringPresenter());

            output.WriteLineForAll($"{_player.Name} has voted for \"{survey.Question.Value}\"");
        }
Beispiel #2
0
 private static IEnumerable <string> GetChoices(Entity.Command command)
 {
     return(OptionParser.ParseOption("c", command));
 }
Beispiel #3
0
 private static string GetSurveyId(Entity.Command command)
 {
     return(OptionParser.ParseOption("i", command)[0]);
 }
Beispiel #4
0
 private static string GetQuestionOption(Entity.Command command)
 {
     return(OptionParser.ParseOption("q", command)[0]);
 }