User.cs 3.0 KB

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