Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. public class UserView : IUsersView, IUserView
  2. {
  3. private UserViewModel[] _users;
  4. private bool _isActive;
  5. private IActionDispatcher _actionDispatcher;
  6.  
  7.  
  8. public UserView(IActionDispatcher actionDispatcher)
  9. {
  10. _isActive = true;
  11. this._actionDispatcher = actionDispatcher;
  12. _users = new UserViewModel[0];
  13. }
  14. public void Start()
  15. {
  16. Console.Clear();
  17. Console.WriteLine("This application is running!");
  18.  
  19. while (_isActive)
  20. {
  21. PrintInstructions();
  22. var input = Console.ReadKey();
  23. InputHandler(input.KeyChar);
  24. }
  25. }
  26.  
  27. private void InputHandler(char input)
  28. {
  29. Console.WriteLine("");
  30. if(input == 'a')
  31. {
  32. this.AddUser();
  33. }
  34. else if (input == 'l')
  35. {
  36. this.DisplayUserList();
  37. }
  38. else if (input == 'q')
  39. {
  40. this.Quit();
  41. }
  42. else
  43. {
  44. Console.WriteLine("Unknown Command");
  45. }
  46.  
  47. }
  48.  
  49.  
  50. private void PrintInstructions()
  51. {
  52. var str1 = @"a - add user";
  53. var str2 = @"l - list users";
  54. var str3 = @"q - quit";
  55.  
  56. var instructions = new List<string> { str1, str2, str3 };
  57.  
  58. Console.WriteLine("choose an option");
  59. foreach (var item in instructions)
  60. {
  61. this.PrintTab(item);
  62. }
  63. }
  64.  
  65. public void Quit()
  66. {
  67. Console.WriteLine("Goodbye");
  68. System.Threading.Thread.Sleep(1000 * 1); // Sleep for 5 minutes
  69. this._isActive = false;
  70. }
  71.  
  72. private void PrintTab(string str)
  73. {
  74. var tabStr = "\t" + str;
  75. Console.WriteLine(tabStr);
  76.  
  77. }
  78.  
  79. public void AddUser()
  80. {
  81. Console.WriteLine("Enter a username");
  82. var name = Console.ReadLine();
  83. var user = new UserViewModel();
  84. user.UserName = name;
  85. var action = new AddUserAction(user);
  86. this._actionDispatcher.Dispatch(action);
  87. }
  88.  
  89. public void Render(UserViewModel[] users)
  90. {
  91. this._users = users;
  92. this.DisplayUserList();
  93. }
  94.  
  95. public void DisplayUserList()
  96. {
  97. Console.WriteLine("User Collection:");
  98.  
  99. foreach (var user in _users)
  100. {
  101. this.PrintTab(user.UserName);
  102. }
  103. }
  104.  
  105. public void Render(UserViewModel user)
  106. {
  107. Console.WriteLine("user:");
  108. var id = "ID: " + user.Id;
  109. var username = "username: " + user.UserName;
  110.  
  111. Console.WriteLine(id);
  112. Console.WriteLine(username);
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement