private static void CheckSurveyIdIsGiven(Entity.Command command) { if (OptionParser.CountOptions("i", command) != 1) { throw new Exception("You must specify the ID"); } }
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\""); } }
private static void CheckChoiceHasBeenGiven(Entity.Command command) { if (!OptionParser.HasOption("c", command)) { throw new Exception("The choice must be defined using the option -c"); } }
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); }
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); }
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"); } }
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); }
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); }
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}\""); }
public abstract void Handle(Entity.Command command, IOutput output);
private static string GetSurveyId(Entity.Command command) { return(OptionParser.ParseOption("i", command)[0]); }
private static IEnumerable <string> GetChoices(Entity.Command command) { return(OptionParser.ParseOption("c", command)); }
private static string GetQuestionOption(Entity.Command command) { return(OptionParser.ParseOption("q", command)[0]); }