mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-04-08 01:51:28 +08:00
完成资源分配前端模块化处理
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
<Compile Include="ModuleElementManagerApp.cs" />
|
||||
<Compile Include="ModuleManagerApp.cs" />
|
||||
<Compile Include="ResourceManagerApp.cs" />
|
||||
<Compile Include="RevelanceManagerApp.cs" />
|
||||
<Compile Include="RoleManagerApp.cs" />
|
||||
<Compile Include="StockManagerApp.cs" />
|
||||
<Compile Include="UserManagerApp.cs" />
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace OpenAuth.App
|
||||
public List<ResourceVM> LoadWithAccess(string accessType, int firstId, int cId)
|
||||
{
|
||||
var listVms = new List<ResourceVM>();
|
||||
if (cId == 0) return listVms;
|
||||
// if (cId == 0) return listVms;
|
||||
|
||||
foreach (var element in _repository.LoadInOrgs(cId))
|
||||
{
|
||||
@@ -137,17 +137,6 @@ namespace OpenAuth.App
|
||||
return listVms;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为用户分配资源
|
||||
/// </summary>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <param name="resIds">资源ID数组</param>
|
||||
public void AssignResForUser(int userId, int[] resIds)
|
||||
{
|
||||
_relevanceRepository.DeleteBy("UserResource", resIds);
|
||||
_relevanceRepository.AddRelevance("UserResource", resIds.ToLookup(u => userId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为角色分配资源
|
||||
/// </summary>
|
||||
@@ -155,8 +144,12 @@ namespace OpenAuth.App
|
||||
/// <param name="resIds">资源ID数组</param>
|
||||
public void AssignResForRole(int roleId, int[] resIds)
|
||||
{
|
||||
_relevanceRepository.DeleteBy("RoleResource", resIds);
|
||||
_relevanceRepository.AddRelevance("RoleResource", resIds.ToLookup(u => roleId));
|
||||
}
|
||||
|
||||
public void DelResForRole(int roleId, int[] resIds)
|
||||
{
|
||||
_relevanceRepository.DeleteBy("RoleResource", resIds.ToLookup(u =>roleId));
|
||||
}
|
||||
}
|
||||
}
|
||||
44
OpenAuth.App/RevelanceManagerApp.cs
Normal file
44
OpenAuth.App/RevelanceManagerApp.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
|
||||
using OpenAuth.App.ViewModel;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RevelanceManagerApp
|
||||
{
|
||||
|
||||
private readonly IRelevanceRepository _relevanceRepository;
|
||||
|
||||
public RevelanceManagerApp(IRelevanceRepository relevanceRepository)
|
||||
{
|
||||
_relevanceRepository = relevanceRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加关联
|
||||
/// <para>比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表</para>
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如"UserResource"</param>
|
||||
public void Assign(string type, int firstId, int[] secIds)
|
||||
{
|
||||
_relevanceRepository.AddRelevance(type, secIds.ToLookup(u => firstId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消关联
|
||||
/// </summary>
|
||||
/// <param name="type">关联的类型,如"UserResource"</param>
|
||||
/// <param name="firstId">The first identifier.</param>
|
||||
/// <param name="secIds">The sec ids.</param>
|
||||
public void UnAssign(string type, int firstId, int[] secIds)
|
||||
{
|
||||
_relevanceRepository.DeleteBy(type, secIds.ToLookup(u =>firstId));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user