User.cs 3.7 KB

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