private void ExecuteCommand(string commandLine) { if (!string.IsNullOrWhiteSpace(commandLine)) { var command = new Command(commandLine); string commandResult; try { switch (command.CommandName) { case "AddTheatre": var addTheatreCmd = new AddThratreCommand(commandLine); commandResult = CommandExecuter.ExecuteAddTheatreCommand(this.DataBase, addTheatreCmd); break; case "PrintAllTheatres": commandResult = CommandExecuter.ExecutePrintAllTheatresCommand(this.DataBase); break; case "AddPerformance": var addPerformanceCmd = new AddPerformanceCommand(commandLine); commandResult = CommandExecuter.ExecuteAddPerformanceCommand(this.DataBase, addPerformanceCmd); break; case "PrintAllPerformances": commandResult = CommandExecuter.ExecutePrintAllPerformancesCommand(this.DataBase); break; case "PrintPerformances": var printPerformances = new PrintPerformancesCommand(commandLine); commandResult = CommandExecuter.ExecutePrintPerformancesCommand(this.DataBase, printPerformances); break; default: commandResult = "Invalid command!"; break; } this.OutputMethod.Output(commandResult); } catch (Exception ex) { OutputMethod.Output("Error: "+ ex.Message); } } }
internal static string ExecuteAddTheatreCommand(IPerformanceDatabase db, AddThratreCommand command) { db.AddTheatre(command.TheatreName); return "Theatre added"; }