Advertisement
MeliDragon

Untitled

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