User.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GreenTree.Nachtragsmanagement.Core.Domain.Config;
  7. using GreenTree.Nachtragsmanagement.Core.Domain.Misc;
  8. namespace GreenTree.Nachtragsmanagement.Core.Domain.User
  9. {
  10. public class User : BaseEntity
  11. {
  12. #region Fields
  13. /// <summary>
  14. /// Current role
  15. /// </summary>
  16. private Role _currentRole;
  17. /// <summary>
  18. /// Rolelist
  19. /// </summary>
  20. private ICollection<Role> _roles;
  21. /// <summary>
  22. /// Notificationlist
  23. /// </summary>
  24. private ICollection<MailNotification> _mailNotifications;
  25. /// <summary>
  26. /// Configitemlist
  27. /// </summary>
  28. private ICollection<UserConfigItem> _userConfigItems;
  29. #endregion
  30. /// <summary>
  31. /// CustomNumber for identification
  32. /// </summary>
  33. public string CustomNumber { get; set; }
  34. /// <summary>
  35. /// Forename
  36. /// </summary>
  37. public string Forename { get; set; }
  38. /// <summary>
  39. /// Lastname
  40. /// </summary>
  41. public string Lastname { get; set; }
  42. /// <summary>
  43. /// Mail-Address
  44. /// </summary>
  45. public string MailAddress { get; set; }
  46. /// <summary>
  47. /// Password
  48. /// </summary>
  49. public string Password { get; set; }
  50. /// <summary>
  51. /// The role the current user is using
  52. /// </summary>
  53. public Role CurrentRole
  54. {
  55. get
  56. {
  57. return _currentRole;
  58. }
  59. set
  60. {
  61. _currentRole = value;
  62. }
  63. }
  64. /// <summary>
  65. /// Determines if there are changes to the user settings
  66. /// </summary>
  67. public bool? IsChanged { get; set; }
  68. /// <summary>
  69. /// Roles the user have
  70. /// </summary>
  71. public virtual ICollection<Role> Roles
  72. {
  73. get { return _roles ?? (_roles = new List<Role>()); }
  74. protected set { _roles = value; }
  75. }
  76. /// <summary>
  77. /// MailNotification related to the user
  78. /// </summary>
  79. public virtual ICollection<MailNotification> MailNotifications
  80. {
  81. get { return _mailNotifications ?? ( _mailNotifications = new List<MailNotification>()); }
  82. protected set { _mailNotifications = value; }
  83. }
  84. /// <summary>
  85. /// UserConfigItems related to the user
  86. /// </summary>
  87. public virtual ICollection<UserConfigItem> UserConfigItems
  88. {
  89. get { return _userConfigItems ?? ( _userConfigItems = new List<UserConfigItem>()); }
  90. protected set { _userConfigItems = value; }
  91. }
  92. #region Helper
  93. /// <summary>
  94. /// Adds missing roles and removes not selected roles
  95. /// </summary>
  96. /// <param name="roles">User roles.</param>
  97. public void SetRoles(ICollection<Role> roles)
  98. {
  99. Roles = roles;
  100. }
  101. /// <summary>
  102. /// Determines if the user is member of role which owns a specific function
  103. /// </summary>
  104. /// <param name="functionName">The name of the function.</param>
  105. public bool HasFunction(string functionName)
  106. {
  107. if (String.IsNullOrEmpty(functionName))
  108. return false;
  109. return
  110. CurrentRole.Functions
  111. .Any(f => f.Name == functionName);
  112. }
  113. #endregion
  114. }
  115. }