User.cs 3.8 KB

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