using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using GreenTree.Nachtragsmanagement.Core.Domain.Config; using GreenTree.Nachtragsmanagement.Core.Domain.Misc; namespace GreenTree.Nachtragsmanagement.Core.Domain.User { public class User : BaseEntity { #region Fields /// /// Current role /// private Role _currentRole; /// /// Rolelist /// private ICollection _roles; /// /// Notificationlist /// private ICollection _mailNotifications; /// /// Configitemlist /// private ICollection _userConfigItems; #endregion /// /// CustomNumber for identification /// public string CustomNumber { get; set; } /// /// Forename /// public string Forename { get; set; } /// /// Lastname /// public string Lastname { get; set; } /// /// Mail-Address /// public string MailAddress { get; set; } /// /// Password /// public string Password { get; set; } /// /// The role the current user is using /// public Role CurrentRole { get { return _currentRole; } set { _currentRole = value; } } /// /// Determines if there are changes to the user settings /// public bool? IsChanged { get; set; } /// /// Roles the user have /// public virtual ICollection Roles { get { return _roles ?? (_roles = new List()); } protected set { _roles = value; } } /// /// MailNotification related to the user /// public virtual ICollection MailNotifications { get { return _mailNotifications ?? ( _mailNotifications = new List()); } protected set { _mailNotifications = value; } } /// /// UserConfigItems related to the user /// public virtual ICollection UserConfigItems { get { return _userConfigItems ?? ( _userConfigItems = new List()); } protected set { _userConfigItems = value; } } #region Helper /// /// Adds missing roles and removes not selected roles /// /// User roles. public void SetRoles(ICollection roles) { Roles = roles; } /// /// Determines if the user is member of role which owns a specific function /// /// The name of the function. public bool HasFunction(string functionName) { if (String.IsNullOrEmpty(functionName)) return false; return CurrentRole.Functions .Any(f => f.Name == functionName); } #endregion } }