You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
1.9 KiB

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
namespace BaseService.BaseData
{
/// <summary>
/// 用户-分支
/// </summary>
public class UserBranch : AuditedAggregateRoot<Guid>
{
/// <summary>
/// 用户ID
/// </summary>
public Guid UserId { get; set; }
// /// <summary>
// /// 用户名称
// /// </summary>
// [NotMapped]
// public string UserName { get; set; }
/// <summary>
/// 分支ID
/// </summary>
public Guid BranchId { get; set; }
// /// <summary>
// /// 分支机构名称
// /// </summary>
// [NotMapped]
// public string BranchName { get; set; }
//
/// <summary>
/// 软删除
/// </summary>
//public bool IsDeleted { get; set; }
public virtual ICollection<UserBranchRole> Roles { get; set; }
public UserBranch(Guid id, Guid userId, Guid branchId) : base(id)
{
UserId = userId;
BranchId = branchId;
Roles = new Collection<UserBranchRole>();
}
public virtual void AddRole(Guid roleId)
{
Check.NotNull(roleId, nameof(roleId));
if (IsInRole(roleId))
{
return;
}
Roles.Add(new UserBranchRole(roleId));
}
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);
}
}
}