public void ParseCommand(string command) { string[] commandParts = command.Split(' '); if (command != string.Empty) { if (command[0] == ':') { ExecuteAdminCommand(commandParts); } else if (ValidCommand(commandParts)) { try { if (commandParts.Count() == 3) { ui.DisplayUserBuysProduct(stregsystem.BuyProduct(Convert.ToInt32(commandParts[2]), Convert.ToInt32(commandParts[1]), commandParts[0])); } else if (commandParts.Count() == 2) { ui.DisplayUserBuysProduct(stregsystem.BuyProduct(Convert.ToInt32(commandParts[1]), commandParts[0])); } else if (commandParts.Count() == 1) { ui.DisplayUserInfo(stregsystem.GetUser(commandParts[0])); } else { ui.DisplayTooManyArgumentsError(); } } catch (Exception e) { if (e is UserNotFoundException) { ui.DisplayUserNotFound(commandParts[0]); } else if (e is InsufficientCreditsException) { ui.DisplayError("Insufficient funds."); } } } else { ui.DisplayError("Not a valid command"); } } else { ui.DisplayError("You must type a command."); } }