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.
91 lines
2.1 KiB
91 lines
2.1 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Collections.ObjectModel;
|
||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using Volo.Abp;
|
||
|
using Volo.Abp.Domain.Entities;
|
||
|
using Volo.Abp.Domain.Entities.Auditing;
|
||
|
using Volo.Abp.MultiTenancy;
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|