Пример #1
0
        public override void Handle(Entity.Command command, IOutput output)
        {
            CheckSurveyIdIsGiven(command);

            var survey = _repository.FindOne(GetSurveyId(command));

            CheckValidity(survey);

            survey.Status = SurveyStatus.Done;

            var request   = _facade.ToSaveSurveyFactory().CreateRequest(survey);
            var presenter = new StopSurveyAsStringPresenter();

            _facade.ToSaveSurveyFactory()
            .CreateExecutor(_repository)
            .Execute(request, presenter);

            output.WriteLineForAll(presenter.ViewModel);
        }
Пример #2
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}\"");
        }