Ejemplo n.º 1
0
 private static void CheckSurveyIdIsGiven(Entity.Command command)
 {
     if (OptionParser.CountOptions("i", command) != 1)
     {
         throw new Exception("You must specify the ID");
     }
 }
Ejemplo n.º 2
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\"");
     }
 }
Ejemplo n.º 3
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");
     }
 }
Ejemplo n.º 4
0
        private Survey CreateSurveyOnInputBasis(Entity.Command command)
        {
            var survey = _repository.Create();

            survey.Player   = _player;
            survey.Question = _textFactory.CreateText(GetQuestionOption(command));
            survey.Choices  = GetChoices(command).Select(choice => _textFactory.CreateText(choice)).ToList();
            survey.Votes    = new List <Domain.Entity.Vote>();

            return(survey);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private static void CheckCommandParametersValidity(Entity.Command command)
        {
            if (OptionParser.CountOptions("q", command) != 1)
            {
                throw new Exception("You must specify a question");
            }

            if (OptionParser.CountOptions("c", command) < 2)
            {
                throw new Exception("You must specify at least 2 choices");
            }
        }
Ejemplo n.º 7
0
        public override void Handle(Entity.Command command, IOutput output)
        {
            CheckCommandParametersValidity(command);

            var survey    = CreateSurveyOnInputBasis(command);
            var request   = _facade.ToSaveSurveyFactory().CreateRequest(survey);
            var presenter = new StartSurveyAsStringPresenter();

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

            output.WriteLineForAll(presenter.ViewModel);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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}\"");
        }
Ejemplo n.º 10
0
 public abstract void Handle(Entity.Command command, IOutput output);
Ejemplo n.º 11
0
 private static string GetSurveyId(Entity.Command command)
 {
     return(OptionParser.ParseOption("i", command)[0]);
 }
Ejemplo n.º 12
0
 private static IEnumerable <string> GetChoices(Entity.Command command)
 {
     return(OptionParser.ParseOption("c", command));
 }
Ejemplo n.º 13
0
 private static string GetQuestionOption(Entity.Command command)
 {
     return(OptionParser.ParseOption("q", command)[0]);
 }