|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BaseService.BaseData;
|
|
|
|
using BaseService.BaseData.BranchManagement;
|
|
|
|
using BaseService.BaseData.Permissions.Dto;
|
|
|
|
using BaseService.BaseData.UserBranchRoleManagement;
|
|
|
|
using BaseService.BaseData.UserBranchRoleManagement.Dto;
|
|
|
|
using BaseService.Permissions;
|
|
|
|
using BaseService.Systems.UserManagement;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Volo.Abp;
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
using Volo.Abp.Authorization;
|
|
|
|
using Volo.Abp.Authorization.Permissions;
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
using Volo.Abp.Identity;
|
|
|
|
using Volo.Abp.PermissionManagement;
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
|
|
namespace BaseService.UserManagement
|
|
|
|
{
|
|
|
|
[Route("api/base/userbranch")]
|
|
|
|
//[Authorize(BaseServicePermissions.UserBranch.Default)]
|
|
|
|
|
|
|
|
public class UserBranchAppService : ApplicationService, IUserBranchAppService
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 角色
|
|
|
|
/// </summary>
|
|
|
|
protected IIdentityRoleRepository IdentityRoleRepository { get; }
|
|
|
|
private readonly IBranchAppService _branchAppService;
|
|
|
|
private readonly IUserAppService _userAppService;
|
|
|
|
private readonly IRepository<UserBranch, Guid> _repository;
|
|
|
|
//权限提供者类
|
|
|
|
private readonly IAbpAuthorizationPolicyProvider _abpAuthorizationPolicyProvider;
|
|
|
|
/// <summary>
|
|
|
|
/// 当前用户
|
|
|
|
/// </summary>
|
|
|
|
protected ICurrentUser CurrentUsers { get; }
|
|
|
|
protected IIdentityUserRepository UserRepository { get; }
|
|
|
|
/// <summary>
|
|
|
|
/// 权限类
|
|
|
|
/// </summary>
|
|
|
|
protected IPermissionGrantRepository PermissionGrantRepository { get; }
|
|
|
|
|
|
|
|
public UserBranchAppService(
|
|
|
|
IRepository<UserBranch, Guid> repository,
|
|
|
|
IIdentityRoleRepository identityRoleRepository,
|
|
|
|
IAbpAuthorizationPolicyProvider abpAuthorizationPolicyProvider,
|
|
|
|
ICurrentUser currentUser,
|
|
|
|
IIdentityUserRepository userRepository,
|
|
|
|
IPermissionGrantRepository permissionGrantRepository,
|
|
|
|
IUserAppService userAppService,
|
|
|
|
IBranchAppService branchAppService)
|
|
|
|
{
|
|
|
|
_repository = repository;
|
|
|
|
IdentityRoleRepository = identityRoleRepository;
|
|
|
|
_abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider;
|
|
|
|
CurrentUsers = currentUser;
|
|
|
|
UserRepository = userRepository;
|
|
|
|
_branchAppService = branchAppService;
|
|
|
|
_userAppService = userAppService;
|
|
|
|
PermissionGrantRepository = permissionGrantRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 添加
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("createUpdate")]
|
|
|
|
//[Authorize(BaseServicePermissions.UserBranch.Create)]
|
|
|
|
public virtual async Task CreateUpdateAsync(CreateOrUpdateUserBranchDto input)
|
|
|
|
{
|
|
|
|
var userBranch = await _repository.FirstOrDefaultAsync(_ => _.UserId == input.UserId && _.BranchId == input.BranchId).ConfigureAwait(false);
|
|
|
|
if (userBranch == null)
|
|
|
|
{
|
|
|
|
//执行添加操作
|
|
|
|
var createUserBranch = new UserBranch(GuidGenerator.Create(),
|
|
|
|
input.UserId,
|
|
|
|
input.BranchId
|
|
|
|
);
|
|
|
|
var userBranchRoles = input.Roles;
|
|
|
|
//选择了角色信息
|
|
|
|
foreach (var role in userBranchRoles)
|
|
|
|
{
|
|
|
|
createUserBranch.AddRole(role.RoleId);
|
|
|
|
}
|
|
|
|
await _repository.InsertAsync(createUserBranch).ConfigureAwait(false);
|
|
|
|
ObjectMapper.Map<UserBranch, UserBranchDto>(createUserBranch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
userBranch.UserId = input.UserId;
|
|
|
|
userBranch.BranchId = input.BranchId;
|
|
|
|
//修改角色信息
|
|
|
|
var getRoleIds = userBranch.Roles.ToList();
|
|
|
|
if (getRoleIds != null)
|
|
|
|
{
|
|
|
|
for (int i = getRoleIds.Count; i > 0; i--)
|
|
|
|
{
|
|
|
|
var role = getRoleIds[i - 1];
|
|
|
|
userBranch.RemoveRole(role.RoleId);
|
|
|
|
}
|
|
|
|
var getRoles = input.Roles;
|
|
|
|
if (getRoles != null)
|
|
|
|
{
|
|
|
|
foreach (var role in getRoles)
|
|
|
|
{
|
|
|
|
userBranch.AddRole(role.RoleId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (input.Roles == null || input.Roles.Count == 0)
|
|
|
|
{
|
|
|
|
await _repository.UpdateAsync(userBranch).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await _repository.UpdateAsync(userBranch, true).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
ObjectMapper.Map<UserBranch, UserBranchDto>(userBranch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//public virtual async Task<UserBranchDto> CreateAsync(CreateOrUpdateUserBranchDto input)
|
|
|
|
//{
|
|
|
|
// var exist = await _repository.FirstOrDefaultAsync(_ => _.UserId == input.UserId && _.BranchId == input.BranchId);
|
|
|
|
// if (exist != null) throw new BusinessException("该资源信息已存在,不要重复添加!");
|
|
|
|
|
|
|
|
// var userBranch = new UserBranch(GuidGenerator.Create(),
|
|
|
|
// input.UserId,
|
|
|
|
// input.BranchId
|
|
|
|
// );
|
|
|
|
// await _repository.InsertAsync(userBranch);
|
|
|
|
// var userBranchRoles = input.Roles;
|
|
|
|
// //选择了角色信息
|
|
|
|
// foreach (var role in userBranchRoles)
|
|
|
|
// {
|
|
|
|
// userBranch.AddRole(role.RoleId);
|
|
|
|
// }
|
|
|
|
// return ObjectMapper.Map<UserBranch, UserBranchDto>(userBranch);
|
|
|
|
//}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 单条删除
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
/// <param name="branchId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("{userId}/{branchId}/delete")]
|
|
|
|
[Authorize(BaseServicePermissions.UserBranch.Delete)]
|
|
|
|
public virtual async Task DeleteUnitAsync(Guid userId, Guid branchId)
|
|
|
|
{
|
|
|
|
await _repository.DeleteAsync(p => p.UserId == userId && p.BranchId == branchId).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据用户ID进行删除
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("{userId}/delete")]
|
|
|
|
[Authorize(BaseServicePermissions.UserBranch.Delete)]
|
|
|
|
public virtual async Task DeleteUnitAsync(Guid userId)
|
|
|
|
{
|
|
|
|
await _repository.DeleteAsync(p => p.UserId == userId).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量删除
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("delete")]
|
|
|
|
[Authorize(BaseServicePermissions.UserBranch.Delete)]
|
|
|
|
public virtual async Task DeleteAsync(List<Guid> ids)
|
|
|
|
{
|
|
|
|
foreach (var id in ids)
|
|
|
|
{
|
|
|
|
await _repository.DeleteAsync(_ => _.Id == id).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改操作
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut]
|
|
|
|
[Route("{id}")]
|
|
|
|
[Authorize(BaseServicePermissions.UserBranch.Update)]
|
|
|
|
public virtual async Task<UserBranchDto> UpdateAsync(Guid id, CreateOrUpdateUserBranchDto input)
|
|
|
|
{
|
|
|
|
var userBranch = await _repository.FirstOrDefaultAsync(_ => _.UserId == input.UserId && _.BranchId == input.BranchId).ConfigureAwait(false);
|
|
|
|
userBranch.UserId = input.UserId;
|
|
|
|
userBranch.BranchId = input.BranchId;
|
|
|
|
//修改角色信息
|
|
|
|
var getRoleIds = userBranch.Roles;
|
|
|
|
if (getRoleIds != null)
|
|
|
|
{
|
|
|
|
foreach (var removerole in getRoleIds)
|
|
|
|
{
|
|
|
|
userBranch.RemoveRole(removerole.RoleId);
|
|
|
|
}
|
|
|
|
var getRoles = input.Roles;
|
|
|
|
if (getRoles != null)
|
|
|
|
{
|
|
|
|
foreach (var role in getRoles)
|
|
|
|
{
|
|
|
|
userBranch.AddRole(role.RoleId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ObjectMapper.Map<UserBranch, UserBranchDto>(userBranch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 查单条数据
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{id}")]
|
|
|
|
public virtual async Task<UserBranchDto> GetAsync(Guid id)
|
|
|
|
{
|
|
|
|
var result = await _repository.GetAsync(id).ConfigureAwait(false);
|
|
|
|
return ObjectMapper.Map<UserBranch, UserBranchDto>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 分页查询
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("paged")]
|
|
|
|
public virtual async Task<PagedResultDto<UserBranchDto>> GetPagedListAsync(GetUserBranchInput input)
|
|
|
|
{
|
|
|
|
var query = _repository
|
|
|
|
.WhereIf(input.UserId.HasValue, _ => _.UserId == input.UserId);
|
|
|
|
var items = await query
|
|
|
|
.Skip(input.SkipCount)
|
|
|
|
.Take(input.MaxResultCount)
|
|
|
|
.ToListAsync().ConfigureAwait(false);
|
|
|
|
var totalCount = await query.CountAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
var dtos = ObjectMapper.Map<List<UserBranch>, List<UserBranchDto>>(items);
|
|
|
|
return new PagedResultDto<UserBranchDto>(totalCount, dtos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 分支列表(输入用户ID)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{userId}/branches")]
|
|
|
|
[AllowAnonymous]
|
|
|
|
public virtual async Task<List<UserBranchDto>> GetUserBranchsAsync(Guid userId)
|
|
|
|
{
|
|
|
|
var dtos = new List<UserBranchDto>();
|
|
|
|
await GetBranchList(userId, dtos).ConfigureAwait(false);
|
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task GetBranchList(Guid userId, List<UserBranchDto> dtos)
|
|
|
|
{
|
|
|
|
var userBranches = _repository.Where(_ => _.UserId == userId);
|
|
|
|
foreach (var query in userBranches)
|
|
|
|
{
|
|
|
|
var branch = await _branchAppService.GetAsync(query.BranchId).ConfigureAwait(false);
|
|
|
|
dtos.Add(new UserBranchDto()
|
|
|
|
{
|
|
|
|
BranchId = query.BranchId,
|
|
|
|
BranchName = branch.Name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 分支列表(当前登录用户)
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("current/branches")]
|
|
|
|
[AllowAnonymous]
|
|
|
|
public virtual async Task<List<UserBranchDto>> GetCurrentUserBranchesAsync()
|
|
|
|
{
|
|
|
|
var dtos = new List<UserBranchDto>();
|
|
|
|
await GetBranchList(CurrentUser.GetId(), dtos).ConfigureAwait(false);
|
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取当前登录用户默认的组织
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("user-branch/{userId}")]
|
|
|
|
[AllowAnonymous]
|
|
|
|
public virtual async Task<UserBranchDto> GetCurrentUserBranchAsync(Guid userId)
|
|
|
|
{
|
|
|
|
var dto = new UserBranchDto();
|
|
|
|
var userBranche = _repository.FirstOrDefault(_ => _.UserId == userId);
|
|
|
|
if (userBranche == null)
|
|
|
|
{
|
|
|
|
throw new BusinessException("当前登录用户不存在!");
|
|
|
|
}
|
|
|
|
var branch = await _branchAppService.GetAsync(userBranche.BranchId).ConfigureAwait(false);
|
|
|
|
dto.BranchId = branch.Id;
|
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取当前登录用户所在组织的所有权限信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="branchId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{branchId}/auth-config")]
|
|
|
|
[AllowAnonymous]
|
|
|
|
public virtual async Task<ApplicationAuthes> GetAuthConfigAsync(Guid branchId)
|
|
|
|
{
|
|
|
|
var authConfig = new ApplicationAuthes();
|
|
|
|
var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync().ConfigureAwait(false);
|
|
|
|
foreach (var policyName in policyNames)
|
|
|
|
{
|
|
|
|
authConfig.Policies[policyName] = true;
|
|
|
|
}
|
|
|
|
var userId = CurrentUser.GetId();
|
|
|
|
|
|
|
|
//获取当前用户的所有权限信息
|
|
|
|
var grantedPermuissions = await GetUserGrantedPermissionsAsync(userId, branchId).ConfigureAwait(false);
|
|
|
|
if (grantedPermuissions == null || grantedPermuissions.Count == 0)
|
|
|
|
{
|
|
|
|
throw new BusinessException("当前登录用户没有任何权限信息,请找管理员进行维护!");
|
|
|
|
}
|
|
|
|
//获取当前用户所在组织的所有角色名
|
|
|
|
var userRoleName = await GetUserRoleNamesAsync(userId, branchId).ConfigureAwait(false);
|
|
|
|
if (userRoleName == null)
|
|
|
|
{
|
|
|
|
throw new BusinessException("当前登录用户没有任何组织信息,请找管理员进行维护!");
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var roleName in userRoleName)
|
|
|
|
{
|
|
|
|
var userPermission = grantedPermuissions.Where(_ => _.ProviderKey == roleName);
|
|
|
|
foreach (var permission in userPermission)
|
|
|
|
{
|
|
|
|
//GrantedPolicies的key键不能相同
|
|
|
|
if (authConfig.GrantedPolicies.ContainsKey(permission.Name))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
authConfig.GrantedPolicies.Add(permission.Name, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return authConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 权限信息(单个用户)(获取权限调用)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual async Task<List<PermissionGrant>> GetUserGrantedPermissionsAsync(Guid userId, Guid branchId)
|
|
|
|
{
|
|
|
|
var permissionGrants = new List<PermissionGrant>();
|
|
|
|
var listRolesName = await GetUserRoleNamesAsync(userId, branchId).ConfigureAwait(false);
|
|
|
|
if (listRolesName != null)
|
|
|
|
{
|
|
|
|
foreach (var rolename in listRolesName)
|
|
|
|
{
|
|
|
|
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, rolename).ConfigureAwait(false);
|
|
|
|
if (permissionGrantsInRole != null)
|
|
|
|
{
|
|
|
|
foreach (var permiss in permissionGrantsInRole)
|
|
|
|
{
|
|
|
|
permissionGrants.Add(permiss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return permissionGrants;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取出用户所在当前组织的所有角色名称(获取权限调用)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual async Task<List<string>> GetUserRoleNamesAsync(Guid userId, Guid branchId)
|
|
|
|
{
|
|
|
|
var userBranch = await _repository.GetAsync(_ => _.UserId == userId && _.BranchId == branchId).ConfigureAwait(false);
|
|
|
|
var userRoles = userBranch.Roles.ToList();
|
|
|
|
//var userRoles = await GetUserRolesAsync(userId, branchId);
|
|
|
|
var roles = await IdentityRoleRepository.GetListAsync().ConfigureAwait(false);
|
|
|
|
return userRoles.Select(role => roles.FirstOrDefault(p => p.Id == role.RoleId)?.Name)
|
|
|
|
.Where(roleName => !string.IsNullOrWhiteSpace(roleName)).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据用户ID、组织ID获取该用户角色信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("userRoles/{userId}/{branchId}")]
|
|
|
|
public virtual async Task<List<UserBranchRole>> GetUserRolesAsync(Guid userId, Guid branchId)
|
|
|
|
{
|
|
|
|
var roleList = new List<UserBranchRole>();
|
|
|
|
var isInRole = _repository.FirstOrDefault(_ => _.UserId == userId && _.BranchId == branchId);
|
|
|
|
if (isInRole != null)
|
|
|
|
{
|
|
|
|
var userBranch = await _repository.GetAsync(_ => _.UserId == userId && _.BranchId == branchId).ConfigureAwait(false);
|
|
|
|
var roles = userBranch.Roles.ToList();
|
|
|
|
foreach (var role in roles)
|
|
|
|
{
|
|
|
|
roleList.Add(new UserBranchRole() { RoleId = role.RoleId });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return roleList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据组织ID查角色信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="branchId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("userRoles/{branchId}")]
|
|
|
|
public virtual List<UserBranchRole> GetBranchRolesAsync(Guid branchId)
|
|
|
|
{
|
|
|
|
var dtos = new List<UserBranchRole>();
|
|
|
|
var isInRole = _repository.Where(_ => _.BranchId == branchId);
|
|
|
|
if (isInRole != null)
|
|
|
|
{
|
|
|
|
foreach (var userRoles in isInRole)
|
|
|
|
{
|
|
|
|
foreach (var role in userRoles.Roles)
|
|
|
|
{
|
|
|
|
dtos.Add(new UserBranchRole() { RoleId = role.RoleId });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dtos;
|
|
|
|
//var roleList = new List<UserBranchRole>();
|
|
|
|
//var isInRole = _repository.Where(_ => _.BranchId == branchId);
|
|
|
|
//if(isInRole!=null)
|
|
|
|
//{
|
|
|
|
// var userBranch = await _repository.GetAsync(_ => _.BranchId == branchId);
|
|
|
|
// var roles = userBranch.Roles.ToList();
|
|
|
|
// foreach (var role in roles)
|
|
|
|
// {
|
|
|
|
// roleList.Add(new UserBranchRole() { RoleId = role.RoleId });
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//return roleList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 根据用户ID查角色信息
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{userId}/userRoles")]
|
|
|
|
public virtual List<UserBranchRole> GetUserRolesAsync(Guid userId)
|
|
|
|
{
|
|
|
|
var dtos = new List<UserBranchRole>();
|
|
|
|
var isInRole = _repository.Where(_ => _.UserId == userId);
|
|
|
|
if (isInRole != null)
|
|
|
|
{
|
|
|
|
foreach (var userRoles in isInRole)
|
|
|
|
{
|
|
|
|
foreach (var role in userRoles.Roles)
|
|
|
|
{
|
|
|
|
dtos.Add(new UserBranchRole() { RoleId = role.RoleId });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|