public string DispatchCommand(string[] commandParams) { string commandName = commandParams[0]; var commandArg = commandParams.Skip(1).ToArray(); string result = string.Empty; switch (commandName) { case "print-info": var printInfo = new PrintInfoCommand(); result = printInfo.Execute(commandArg); break; case "buy-ticket": var buyTicket = new BuyTicketCommand(); result = buyTicket.Execute(commandArg); break; case "publish-review": var publishReview = new PublishReviewCommand(); result = publishReview.Execute(commandArg); break; case "print-reviews": var printReview = new PrintReviewsCommand(); result = printReview.Execute(commandArg); break; case "ChangeTripStatus": var changeTripStatusCommand = new ChangeTripStatusCommand(); result = changeTripStatusCommand.Execute(commandArg); break; default: throw new InvalidOperationException("Invalid command!"); } return(result); }
public string DispatchCommand(string[] commandParameters) { string command = commandParameters[0]; string result = null; switch (command.ToLower()) { case "print-info": result = PrintInfoCommand.Execute(commandParameters); break; case "buy-ticket": result = BuyTicketCommand.Execute(commandParameters); break; case "publish-review": result = PublishReviewCommand.Execute(commandParameters); break; case "print-reviews": result = PrintReviewsCommand.Execute(commandParameters); break; case "change-trip-status": result = ChangeTripStatusCommand.Execute(commandParameters); break; case "exit": result = ExitCommand.Execute(commandParameters); break; default: throw new InvalidOperationException($"Command {command} not valid!"); } return(result); }