예제 #1
0
 private static void CheckSurveyIdIsGiven(Entity.Command command)
 {
     if (!OptionParser.HasOption("i", command))
     {
         throw new Exception("The survey ID must be defined using the option -i. You can find the ID by using the command \"/survey list -a\"");
     }
 }
예제 #2
0
 private static void CheckChoiceHasBeenGiven(Entity.Command command)
 {
     if (!OptionParser.HasOption("c", command))
     {
         throw new Exception("The choice must be defined using the option -c");
     }
 }
예제 #3
0
        public override void Handle(Entity.Command command, IOutput output)
        {
            var presenter = new GetAllSurveysAsStringPresenter(
                "",
                OptionParser.HasOption("a", command),
                OptionParser.HasOption("i", command),
                OptionParser.HasOption("r", command));

            _facade.ToGetAllSurveys().CreateExecutor(_repository).Execute(presenter);

            output.WriteLineForAll(presenter.ViewModel);
        }
예제 #4
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}\"");
        }