using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Abp.Domain.Entities.Auditing; using IwbZero.Authorization.Users; using Microsoft.AspNet.Identity; namespace IwbZero.Authorization.Roles { public abstract class IwbSysRole : RoleBase, IRole, IFullAudited where TUser : IwbSysUser { public virtual TUser CreatorUser { get; set; } public virtual TUser LastModifierUser { get; set; } public virtual TUser DeleterUser { get; set; } } [Table("Sys_Roles")] public abstract class RoleBase : FullAuditedEntity { public const string AdminRoleName = "admin"; public const string AdminRoleDisplayName = "admin"; /// /// Maximum length of the property. /// public const int MaxDisplayNameLength = 64; public const int MaxDescriptionLength = 1000; /// /// Maximum length of the property. /// public const int MaxNameLength = 32; /// /// Unique name of this role. /// [Required] [StringLength(MaxNameLength)] public virtual string Name { get; set; } /// /// Display name of this role. /// [Required] [StringLength(MaxDisplayNameLength)] public virtual string RoleDisplayName { get; set; } [StringLength(MaxDescriptionLength)] public virtual string Description { get; set; } public int RoleType { get; set; } /// /// Is this a static role? /// Static roles can not be deleted, can not change their name. /// They can be used programmatically. /// public virtual bool IsStatic { get; set; } /// /// Is this role will be assigned to new users as default? /// public virtual bool IsDefault { get; set; } ///// ///// List of permissions of the role. ///// //[ForeignKey("RoleId")] //public virtual ICollection Permissions { get; set; } protected RoleBase() { Name = Guid.NewGuid().ToString("N"); } protected RoleBase(string roleDisplayName) : this() { RoleDisplayName = roleDisplayName; } protected RoleBase(string name, string displayName) : this(displayName) { Name = name; } public override string ToString() { return $"[Role {Id}, Name={Name}]"; } } }