/FamilyModels/Person.cs

https://bitbucket.org/whemmingsson/family.net
C# | 154 lines | 74 code | 25 blank | 55 comment | 4 complexity | 5de7ec30e92d80cfa40dde664ff2186a MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace FamilyModels
  7. {
  8. /// <summary>
  9. /// Models a person
  10. /// </summary>
  11. public class Person
  12. {
  13. #region Fields
  14. private readonly List<Relationship> _relations;
  15. private readonly List<Event> _events;
  16. private int _internalId;
  17. #endregion
  18. #region Constructors
  19. /// <summary>
  20. /// Public (default) constructor
  21. /// </summary>
  22. public Person()
  23. {
  24. _relations = new List<Relationship>();
  25. _events = new List<Event>();
  26. }
  27. #endregion
  28. #region Properties
  29. /// <summary>
  30. /// The XML-based ID is used to parse into the internal id. Only used by the import job
  31. /// </summary>
  32. public void SetId(string id)
  33. {
  34. var val = id;
  35. if (!val.Contains("I")) return;
  36. int outId;
  37. if (int.TryParse(val.Substring(1), out outId))
  38. {
  39. _internalId = outId;
  40. }
  41. }
  42. /// <summary>
  43. /// Id of the person
  44. /// </summary>
  45. public int Id { set { _internalId = value; } get { return _internalId; } }
  46. /// <summary>
  47. /// Sex of the person
  48. /// </summary>
  49. public Sex Sex { set; get; }
  50. /// <summary>
  51. /// Name of the person
  52. /// </summary>
  53. public Name Name { set; get; }
  54. /// <summary>
  55. /// The birth event of the person
  56. /// </summary>
  57. public Event Birth { set; get; }
  58. /// <summary>
  59. /// Death event of the person
  60. /// </summary>
  61. public Event Death { set; get; }
  62. /// <summary>
  63. /// Parses the name into a quick representation of the whole name
  64. /// </summary>
  65. public string QuickName
  66. {
  67. get
  68. {
  69. if (Name != null)
  70. {
  71. return Name.GivenName + " " + Name.FamilyName;
  72. }
  73. return string.Empty;
  74. }
  75. }
  76. /// <summary>
  77. /// All persons relations
  78. /// </summary>
  79. //public List<Relationship> Relations { get { return _relations; } }
  80. #endregion
  81. #region Methods
  82. /// <summary>
  83. /// Add a relationship object to the internal list of relations
  84. /// </summary>
  85. /// <param name="relation">The new relation</param>
  86. public void AddRelation(Relationship relation)
  87. {
  88. _relations.Add(relation);
  89. }
  90. /// <summary>
  91. /// Add a strongly typed relation to another existing person
  92. /// </summary>
  93. /// <param name="person">The related person</param>
  94. /// <param name="type">The type of relation</param>
  95. public void AddRelation(Person person, Relationship.RelationType type)
  96. {
  97. _relations.Add(new Relationship {Person = person, Type = type});
  98. }
  99. /// <summary>
  100. /// Add a loosley typed relation to another existing person
  101. /// </summary>
  102. /// <param name="name">The related persons name</param>
  103. /// <param name="type">The type of relation</param>
  104. public void AddRelation(Name name, Relationship.RelationType type)
  105. {
  106. _relations.Add(new Relationship { Name=name, Type = type });
  107. }
  108. /// <summary>
  109. /// Add an event to the person
  110. /// </summary>
  111. /// <param name="eEvent">The event to add</param>
  112. public void AddEvent(Event eEvent)
  113. {
  114. _events.Add(eEvent);
  115. }
  116. /// <summary>
  117. /// Add an event using parameters
  118. /// </summary>
  119. /// <param name="type">Type of event</param>
  120. /// <param name="date">Date of the event</param>
  121. /// <param name="place">Place of the event</param>
  122. [Obsolete("[Deprecated]")]
  123. public void AddEvent(Event.EventType type, string date, string place)
  124. {
  125. throw new NotImplementedException("This method is deprecated");
  126. }
  127. #endregion
  128. }
  129. }