using BaseService.RelationBaseData; using JetBrains.Annotations; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Volo.Abp; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; namespace BaseService.BaseData { public class Branch : AuditedAggregateRoot, ISoftDelete { public Guid? TenantId { get; set; } /// /// 机构分类:1.公司;2.组织;3.部门;4.供应商 /// public short CategoryId { get; set; } public Guid? Pid { get; set; } public string Name { get; set; } public string FullName { get; set; } public int Sort { get; set; } /// /// 是否子集 /// public bool Leaf { get; set; } /// /// 级联 /// public string CascadeId { get; set; } public bool Enabled { get; set; } public bool IsDeleted { get; set; } public virtual ICollection Roles { get; set; } public Branch(Guid id, Guid? tenantId, short categoryId, Guid? pid, [NotNull] string name, string fullName, int sort, bool leaf, bool enabled) { TenantId = tenantId; Id = id; CategoryId = categoryId; Pid = pid; Name = name; FullName = fullName; Sort = sort; Enabled = enabled; Leaf = leaf; Roles = new Collection(); } public virtual void AddRole(Guid roleId) { Check.NotNull(roleId, nameof(roleId)); if (IsInRole(roleId)) { return; } Roles.Add(new BranchRole(roleId, Id)); } public virtual void RemoveRole(Guid roleId) { Check.NotNull(roleId, nameof(roleId)); if (!IsInRole(roleId)) { return; } Roles.RemoveAll(r => r.RoleId == roleId); } public virtual bool IsInRole(Guid roleId) { Check.NotNull(roleId, nameof(roleId)); return Roles.Any(r => r.RoleId == roleId); } ///// ///// 机构分类:1.公司;2.分支;3.部门;4.供应商 ///// //public short CategoryId { get; set; } //public Guid? Pid { get; set; } //public string Name { get; set; } //public string FullName { get; set; } //public int Sort { get; set; } //public bool Enabled { get; set; } //public bool IsDeleted { get; set; } //public virtual ICollection Roles { get; set; } //public Branch(Guid id, short categoryId, Guid? pid, [NotNull] string name, string fullName, int sort, bool enabled) //{ // Id = id; // CategoryId = categoryId; // Pid = pid; // Name = name; // FullName = fullName; // Sort = sort; // Enabled = enabled; // Roles = new Collection(); //} //public virtual void AddRole(Guid roleId) //{ // Check.NotNull(roleId, nameof(roleId)); // if (IsInRole(roleId)) // { // return; // } // Roles.Add(new BranchRole(roleId, Id)); //} //public virtual void RemoveRole(Guid roleId) //{ // Check.NotNull(roleId, nameof(roleId)); // if (!IsInRole(roleId)) // { // return; // } // Roles.RemoveAll(r => r.RoleId == roleId); //} //public virtual bool IsInRole(Guid roleId) //{ // Check.NotNull(roleId, nameof(roleId)); // return Roles.Any(r => r.RoleId == roleId); //} } }