using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using GreenTree.Nachtragsmanagement.Core.Domain.Misc; namespace GreenTree.Nachtragsmanagement.Core.Domain.User { public class User : BaseEntity { #region Fields /// /// Rolelist /// private ICollection _roles; /// /// Notificationlist /// private ICollection _mailNotifications; #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; 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; } } #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 Roles .SelectMany(s => s.Functions) .Any(f => f.Name == functionName); } #endregion } }