Advertisement
nassss

Untitled

Jan 30th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text;
  4. using System;
  5. using OlympicGames.Core.Commands.Abstracts;
  6. using OlympicGames.Core.Contracts;
  7. using OlympicGames.Olympics.Contracts;
  8. using OlympicGames.Olympics.Olympics;
  9.  
  10. namespace OlympicGames.Core.Commands
  11. {
  12. public class ListOlympiansCommand : Command
  13. {
  14. public ListOlympiansCommand(IList<string> commandLine, IOlympicCommittee committee)
  15. : base(commandLine, committee)
  16. {
  17. }
  18.  
  19. public override string Execute()
  20. {
  21. var output = new StringBuilder();
  22.  
  23. string key = "firstname";
  24. string order = "asc";
  25. if (this.Committee.Olympians.Count == 0)
  26. {
  27. return "NO OLYMPIANS ADDED";
  28. }
  29. if (this.CommandParameters.Count == 0)
  30. {
  31. Console.WriteLine(($"Sorted by [{key}] in [order: {order}]"));
  32. this.Committee.Olympians.OrderBy(o => o.FirstName);
  33. }
  34. else if (this.CommandParameters.Count == 1)
  35. {
  36. if (this.CommandParameters[0] == "firstname" || this.CommandParameters[0] == "lastname" || this.CommandParameters[0] == "country")
  37. {
  38. key = CommandParameters[0];
  39. Console.WriteLine(($"Sorted by [{key}] in [order: {order}]"));
  40. if (key == "firstname")
  41. {
  42. this.Committee.Olympians.OrderBy(o => o.FirstName);
  43. }
  44. else if (key == "lastname")
  45. {
  46. this.Committee.Olympians.OrderBy(o => o.LastName);
  47. }
  48. else
  49. {
  50. this.Committee.Olympians.OrderBy(o => o.Country);
  51. }
  52. }
  53. else if (this.CommandParameters[0] == "asc" || this.CommandParameters[0] == "dsc")
  54. {
  55. order = CommandParameters[0];
  56. Console.WriteLine(($"Sorted by [{key}] in [order: {order}]"));
  57. if (order == "asc")
  58. {
  59. this.Committee.Olympians.OrderBy(o => o.FirstName);
  60. }
  61. else
  62. {
  63. this.Committee.Olympians.OrderByDescending(o => o.FirstName);
  64. }
  65. }
  66. }
  67. else if (this.CommandParameters.Count == 2)
  68. {
  69. if (this.CommandParameters[0] == "firstname" || this.CommandParameters[0] == "lastname" || this.CommandParameters[0] == "country")
  70. {
  71. key = CommandParameters[0];
  72. if (key == "firstname")
  73. {
  74. this.Committee.Olympians.OrderBy(o => o.FirstName);
  75. }
  76. else if (key == "lastname")
  77. {
  78. this.Committee.Olympians.OrderBy(o => o.LastName);
  79. }
  80. else
  81. {
  82. this.Committee.Olympians.OrderBy(o => o.Country);
  83. }
  84. }
  85. if (this.CommandParameters[0] == "asc" || this.CommandParameters[0] == "dsc")
  86. {
  87. order = CommandParameters[0];
  88. if (order == "asc")
  89. {
  90. this.Committee.Olympians.OrderBy(o => o.FirstName);
  91. }
  92. else
  93. {
  94. this.Committee.Olympians.OrderByDescending(o => o.FirstName);
  95. }
  96. }
  97. Console.WriteLine(($"Sorted by [{key}] in [order: {order}]"));
  98.  
  99. }
  100. foreach (var item in Committee.Olympians)
  101. {
  102. output.AppendLine(item.Print());
  103. }
  104. return output.ToString().Trim();
  105. }
  106.  
  107.  
  108.  
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement