Advertisement
dxeqtr

Untitled

Jan 14th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace BoardR
  7. {
  8. class BoardItem
  9. {
  10.  
  11. string title;
  12. DateTime dueDate;
  13. StatusStages status = StatusStages.Open;
  14.  
  15. List<EventLog> historyEvents = new List<EventLog>();
  16.  
  17. public StatusStages Status
  18. {
  19. get
  20. {
  21. return this.status;
  22. }
  23. set
  24. {
  25. this.status = value;
  26. }
  27. }
  28.  
  29. public DateTime DueDate
  30. {
  31. get { return this.dueDate; }
  32.  
  33. set { this.dueDate = value; }
  34. }
  35.  
  36. public string Title
  37. {
  38. get
  39. {
  40. return this.title;
  41. }
  42. set
  43. {
  44. // validate
  45. if (ValidateTitle(title) && ValidateDate(dueDate))
  46. {
  47. this.title = value;
  48. }
  49.  
  50. }
  51. }
  52.  
  53. public BoardItem(string title, DateTime dueDate)
  54. {
  55. this.Title = title; // ТУК НА МЕН ВИНАГИ МИ ДАВА exeption ?!??!?!?!??!
  56. this.DueDate = dueDate;
  57.  
  58. this.historyEvents.Add(new EventLog("Board item was created"));
  59. }
  60.  
  61. public void AdvanceStatus()
  62. {
  63. if (this.status != StatusStages.Verified)
  64. this.status++;
  65.  
  66. }
  67.  
  68. public void RevertStatus()
  69. {
  70. if (this.status != StatusStages.Open)
  71. this.status--;
  72. }
  73.  
  74. public void AddingItems(string title, DateTime dueDate)
  75. {
  76. EventLog eventItself = new EventLog(title);
  77. historyEvents.Add(eventItself);
  78. }
  79.  
  80. public string ViewHistory()
  81. {
  82. return string.Join("\n", this.historyEvents.Select(x => x.ViewInfo()));
  83. }
  84.  
  85. public string ViewInfo()
  86. {
  87. return $"'{title}', [{status}|{dueDate.ToString("dd-MM-yyyy")}]";
  88. }
  89.  
  90. private static bool ValidateDate(DateTime dueDate)
  91. {
  92. if (dueDate <= DateTime.Now)
  93. {
  94. throw new ArgumentException("Due date cannot be in the past");
  95. }
  96. else
  97. {
  98. return true;
  99. }
  100. }
  101.  
  102. private static bool ValidateTitle(string itemTitle)
  103. {
  104. if (string.IsNullOrEmpty(itemTitle))
  105. {
  106. throw new ArgumentException("Title cannot be null or empty");
  107. }
  108. else if (itemTitle.Length < 5 || itemTitle.Length > 30)
  109. {
  110. throw new ArgumentException("Title must be between 5 and 30 chars");
  111. }
  112. else
  113. {
  114. return true;
  115. }
  116. }
  117.  
  118. }
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement