using System; using System.Collections.ObjectModel; using System.Linq; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; namespace Sanhe.Abp.MenuManagement { public class Permission : AuditedEntity, IMultiTenant { public virtual Guid? TenantId { get; protected set; } public virtual string Key { get; protected set; } public virtual string Name { get; protected set; } public virtual Guid GroupId { get; protected set; } public virtual PermissionGroup Group { get; protected set; } public virtual Guid? ParentId { get; set; } public virtual Permission Parent { get; set; } public virtual Collection Children { get; set; } protected Permission() { } public Permission(Guid id, string key, string name, Guid groupId) { Id = id; Key = key; Name = name; GroupId = groupId; Children = new Collection(); } public virtual Permission AddChildren(Guid id, string key, string name) { if (Children.Any(x => x.Key == key)) { throw new Volo.Abp.UserFriendlyException("权限名重复"); } var page = new Permission(id, key, name, GroupId); page.Parent = this; page.ParentId = Id; Children.Add(page); return page; } } }