forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoleModulePermissionServices.cs
67 lines (58 loc) · 2.43 KB
/
RoleModulePermissionServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Blog.Core.Services.BASE;
using Blog.Core.Model.Models;
using Blog.Core.IServices;
using Blog.Core.IRepository;
using System.Threading.Tasks;
using System.Collections.Generic;
using Blog.Core.Common;
using System.Linq;
namespace Blog.Core.Services
{
/// <summary>
/// RoleModulePermissionServices 应用服务
/// </summary>
public class RoleModulePermissionServices : BaseServices<RoleModulePermission>, IRoleModulePermissionServices
{
readonly IRoleModulePermissionRepository _dal;
readonly IModuleRepository _moduleRepository;
readonly IRoleRepository _roleRepository;
// 将多个仓储接口注入
public RoleModulePermissionServices(IRoleModulePermissionRepository dal, IModuleRepository moduleRepository, IRoleRepository roleRepository)
{
this._dal = dal;
this._moduleRepository = moduleRepository;
this._roleRepository = roleRepository;
base.BaseDal = dal;
}
/// <summary>
/// 获取全部 角色接口(按钮)关系数据
/// </summary>
/// <returns></returns>
[Caching(AbsoluteExpiration = 10)]
public async Task<List<RoleModulePermission>> GetRoleModule()
{
var roleModulePermissions = await base.Query(a => a.IsDeleted == false);
var roles = await _roleRepository.Query(a => a.IsDeleted == false);
var modules = await _moduleRepository.Query(a => a.IsDeleted == false);
//var roleModulePermissionsAsync = base.Query(a => a.IsDeleted == false);
//var rolesAsync = _roleRepository.Query(a => a.IsDeleted == false);
//var modulesAsync = _moduleRepository.Query(a => a.IsDeleted == false);
//var roleModulePermissions = await roleModulePermissionsAsync;
//var roles = await rolesAsync;
//var modules = await modulesAsync;
if (roleModulePermissions.Count > 0)
{
foreach (var item in roleModulePermissions)
{
item.Role = roles.FirstOrDefault(d => d.Id == item.RoleId);
item.Module = modules.FirstOrDefault(d => d.Id == item.ModuleId);
}
}
return roleModulePermissions;
}
public async Task<List<RoleModulePermission>> TestModelWithChildren()
{
return await _dal.WithChildrenModel();
}
}
}