forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserRoleController.cs
More file actions
91 lines (80 loc) · 2.51 KB
/
UserRoleController.cs
File metadata and controls
91 lines (80 loc) · 2.51 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.Threading.Tasks;
using Blog.Core.IServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Blog.Core.Controllers
{
/// <summary>
/// 用户角色关系
/// 【无权限】
/// </summary>
[Produces("application/json")]
[Route("api/[controller]/[action]")]
[ApiController]
[AllowAnonymous]
public class UserRoleController : Controller
{
readonly ISysUserInfoServices _sysUserInfoServices;
readonly IUserRoleServices _userRoleServices;
readonly IRoleServices _roleServices;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="sysUserInfoServices"></param>
/// <param name="userRoleServices"></param>
/// <param name="roleServices"></param>
public UserRoleController(ISysUserInfoServices sysUserInfoServices, IUserRoleServices userRoleServices, IRoleServices roleServices)
{
this._sysUserInfoServices = sysUserInfoServices;
this._userRoleServices = userRoleServices;
this._roleServices = roleServices;
}
/// <summary>
/// 新建用户
/// </summary>
/// <param name="loginName"></param>
/// <param name="loginPwd"></param>
/// <returns></returns>
[HttpGet]
public async Task<object> AddUser(string loginName, string loginPwd)
{
var model = await _sysUserInfoServices.SaveUserInfo(loginName, loginPwd);
return Ok(new
{
success = true,
data = model
});
}
/// <summary>
/// 新建Role
/// </summary>
/// <param name="roleName"></param>
/// <returns></returns>
[HttpGet]
public async Task<object> AddRole(string roleName)
{
var model = await _roleServices.SaveRole(roleName);
return Ok(new
{
success = true,
data = model
});
}
/// <summary>
/// 新建用户角色关系
/// </summary>
/// <param name="uid"></param>
/// <param name="rid"></param>
/// <returns></returns>
[HttpGet]
public async Task<object> AddUserRole(int uid, int rid)
{
var model = await _userRoleServices.SaveUserRole(uid, rid);
return Ok(new
{
success = true,
data = model
});
}
}
}