Advertisement
MeliDragon

Untitled

Apr 15th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. public class ListBugsCommand : BaseCommand
  2. {
  3. public const int ExpectedNumberOfArguments = 2;
  4.  
  5. public ListBugsCommand(IList<string> commandParameters, IRepository repository)
  6. : base(commandParameters, repository)
  7. {
  8. }
  9.  
  10. public override string Execute()
  11. {
  12. string filterByCommand = CommandParameters[0];
  13.  
  14. string sortByCommand = CommandParameters[1];
  15. var task = Repository.Tasks.OfType<Bug>().ToList();
  16. StringBuilder stringBuilder = new StringBuilder();
  17.  
  18. if (filterByCommand == "FilterActive")
  19. {
  20. List<Bug> bugsActive = null;
  21. switch (sortByCommand)
  22. {
  23. case "SortedTitle":
  24. bugsActive = task.
  25. Where(bug => bug.Status == BugStatusType.Active).
  26. OrderBy(bug => bug.Title).ToList();
  27. break;
  28. case "SortedPriority":
  29. bugsActive = task.
  30. Where(bug => bug.Status == BugStatusType.Active).
  31. OrderBy(bug => bug.Priority == PriorityType.High).
  32. ThenBy(bug => bug.Priority == PriorityType.Medium)
  33. .ToList();
  34. break;
  35. case "SortedSeverity":
  36. bugsActive = task.
  37. Where(bug => bug.Status == BugStatusType.Active).
  38. OrderBy(bug => bug.Severity == SeverityType.Critical).
  39. ThenBy(bug => bug.Severity == SeverityType.Major).
  40. ToList();
  41. break;
  42. default:
  43. throw new InvalidUserInputException("The input sort command is incorrect!");
  44. }
  45.  
  46. if (bugsActive.Count == 0)
  47. {
  48. throw new InvalidUserInputException("None of the logged bugs correspond to your search parameters!");
  49. }
  50.  
  51. foreach (Bug bug in bugsActive)
  52. {
  53. stringBuilder.AppendLine(bug.ToString());
  54. stringBuilder.AppendLine(StringGenerator('*', 15));
  55. }
  56. }
  57. else if (filterByCommand == "FilterFixed")
  58. {
  59. List<Bug> bugsFixed = null;
  60. switch (sortByCommand)
  61. {
  62. case "SortedTitle":
  63. bugsFixed = task.
  64. Where(bug => bug.Status == BugStatusType.Fixed).
  65. OrderBy(bug => bug.Title).ToList(); ;
  66. break;
  67. case "SortedPriority":
  68. bugsFixed = task.
  69. Where(bug => bug.Status == BugStatusType.Fixed).
  70. OrderBy(bug => bug.Priority == PriorityType.High).
  71. ThenBy(bug => bug.Priority == PriorityType.Medium).
  72. ThenBy(bug => bug.Priority == PriorityType.Low).ToList();
  73. break;
  74. case "SortedSeverity":
  75. bugsFixed = task.
  76. Where(bug => bug.Status == BugStatusType.Fixed).
  77. OrderBy(bug => bug.Severity == SeverityType.Critical).
  78. ThenBy(bug => bug.Severity == SeverityType.Major).
  79. ThenBy(bug => bug.Severity == SeverityType.Minor).
  80. ToList();
  81. break;
  82. default:
  83. throw new InvalidUserInputException("The input sort command is incorrect!");
  84. }
  85.  
  86. if (bugsFixed.Count == 0)
  87. {
  88. throw new InvalidUserInputException("None of the logged bugs correspond to your search parameters!");
  89. }
  90.  
  91. foreach (Bug bug in bugsFixed)
  92. {
  93. stringBuilder.AppendLine(bug.ToString());
  94. stringBuilder.AppendLine(StringGenerator('*', 15));
  95. }
  96.  
  97.  
  98. }
  99. else if(filterByCommand == "FilterAssignee")
  100. {
  101. List<Bug> bugsAssignee = null;
  102. switch (sortByCommand)
  103. {
  104. case "SortedTitle":
  105. bugsAssignee = task.
  106. Where(bug => bug.Assignee != null).
  107. OrderBy(bug => bug.Title).ToList(); ;
  108. break;
  109. case "SortedPriority":
  110. bugsAssignee = task.
  111. Where(bug => bug.Assignee != null).
  112. OrderBy(bug => bug.Priority == PriorityType.High).
  113. ThenBy(bug => bug.Priority == PriorityType.Medium).
  114. ToList();
  115. break;
  116. case "SortedSeverity":
  117. bugsAssignee = task.
  118. Where(bug => bug.Assignee != null).
  119. OrderBy(bug => bug.Severity == SeverityType.Critical).
  120. ThenBy(bug => bug.Severity == SeverityType.Major).
  121. ToList();
  122. break;
  123. default:
  124. throw new InvalidUserInputException("The input sort command is incorrect!");
  125. }
  126.  
  127. if (bugsAssignee.Count == 0)
  128. {
  129. throw new InvalidUserInputException("None of the logged bugs correspond to your search parameters!");
  130. }
  131.  
  132. foreach (Bug bug in bugsAssignee)
  133. {
  134. stringBuilder.AppendLine(bug.ToString());
  135. stringBuilder.AppendLine(StringGenerator('*', 15));
  136. }
  137. }
  138. else
  139. {
  140. throw new InvalidUserInputException("The input filter command is incorrect!");
  141. }
  142.  
  143. return stringBuilder.ToString().Trim();
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement