diff --git a/FAuth/Controllers/api/App_RoleGroupController.cs b/FAuth/Controllers/api/App_RoleGroupController.cs
new file mode 100644
index 0000000..38789bf
--- /dev/null
+++ b/FAuth/Controllers/api/App_RoleGroupController.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Linq;
+using FAuth.DataBase.Tables;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+
+namespace FAuth.Controllers.api
+{
+ ///
+ /// 应用角色组对应
+ ///
+ public class App_RoleGroupController:ApiControllerBase
+ {
+ public App_RoleGroupController(ILogger logger,IServiceProvider service) : base(logger,service) {
+ }
+ ///
+ /// 绑定指定应用和角色组
+ ///
+ /// 应用编号
+ /// 角色组编号
+ /// 是否成功
+ [HttpPost]
+ public bool Binding(int appId,int roleGroupId) {
+ var aQu = this.Db.Apps.Where(m => m.Id == appId);
+ if(!aQu.Any()) {
+ throw new Exception("没有找到指定的应用");
+ }
+ var rQu = this.Db.RoleGroups.Where(m => m.Id == roleGroupId);
+ if(!rQu.Any()) {
+ throw new Exception("没有找到指定的角色组");
+ }
+ var arQu = this.Db.App_RoleGroups.Where(m => m.AppId == appId && m.RoleGroupId == roleGroupId);
+ if(!arQu.Any()) {
+ var model = new App_RoleGroup {
+ AppId = appId,
+ RoleGroupId = roleGroupId,
+ };
+ this.Db.Entry(model).State = EntityState.Added;
+ this.Db.SaveChangesAsync().Wait();
+ }
+ return true;
+ }
+ ///
+ /// 解除指定应用和角色组绑定
+ ///
+ /// 应用编号
+ /// 角色组编号
+ /// 解绑是否成功
+ [HttpPost]
+ public bool Unbind(int appId,int roleGroupId) {
+ var aQu = this.Db.Apps.Where(m => m.Id == appId);
+ if(!aQu.Any()) {
+ throw new Exception("没有找到指定的应用");
+ }
+ var rQu = this.Db.RoleGroups.Where(m => m.Id == roleGroupId);
+ if(!rQu.Any()) {
+ throw new Exception("没有找到指定的角色组");
+ }
+ var arQu = this.Db.App_RoleGroups.Where(m => m.AppId == appId && m.RoleGroupId == roleGroupId);
+ if(arQu.Any()) {
+ foreach(var item in arQu) {
+ this.Db.Entry(item).State = EntityState.Deleted;
+ }
+ this.Db.SaveChangesAsync().Wait();
+ }
+ return true;
+ }
+ }
+}
diff --git a/FAuth/Controllers/api/RoleController.cs b/FAuth/Controllers/api/RoleController.cs
index a30e8c0..b74e94c 100644
--- a/FAuth/Controllers/api/RoleController.cs
+++ b/FAuth/Controllers/api/RoleController.cs
@@ -2,6 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Falcon.Extend;
+using FAuth.DataBase.Tables;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace FAuth.Controllers.api
@@ -13,6 +17,50 @@ namespace FAuth.Controllers.api
{
public RoleController(ILogger logger,IServiceProvider service) : base(logger,service) {
}
+
+ ///
+ /// 添加新角色
+ ///
+ /// 角色名称
+ /// 角色说明
+ /// 角色信息
+ [HttpPost]
+ [ProducesResponseType(typeof(Roles),200)]
+ public Roles AddNewRole(string roleName,string description) {
+ if(roleName.IsNullOrEmpty()) {
+ throw new ArgumentNullException(nameof(roleName));
+ }
+ var qu = this.Db.Roles.Where(m => m.Name == roleName);
+ if(qu.Any()) {
+ throw new Exception($"角色{roleName}已经存在,不可以重复创建!");
+ }
+ var newRole = new Roles {
+ Name = roleName,
+ Description = description,
+ };
+ this.Db.Entry(newRole).State = EntityState.Added;
+ this.Db.SaveChangesAsync().Wait();
+ return newRole;
+ }
+
+ ///
+ /// 查询角色是否注册
+ ///
+ /// 角色名称
+ ///
+ [HttpPost]
+ [ProducesResponseType(typeof(Roles),200)]
+ public Roles GetApps(string roleName) {
+ if(string.IsNullOrEmpty(roleName))
+ throw new ArgumentException("message",nameof(roleName));
+ var qu = this.Db.Roles.Where(m => m.Name == roleName);
+ if(qu.Any()) {
+ return qu.First();
+ } else {
+ throw new Exception("没有找到该角色");
+ }
+ }
+
}
}
diff --git a/FAuth/Controllers/api/RoleGroupController.cs b/FAuth/Controllers/api/RoleGroupController.cs
index b0384cb..8abf9bb 100644
--- a/FAuth/Controllers/api/RoleGroupController.cs
+++ b/FAuth/Controllers/api/RoleGroupController.cs
@@ -1,4 +1,9 @@
using System;
+using System.Linq;
+using Falcon.Extend;
+using FAuth.DataBase.Tables;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace FAuth.Controllers.api
@@ -10,6 +15,50 @@ namespace FAuth.Controllers.api
{
public RoleGroupController(ILogger logger,IServiceProvider service) : base(logger,service) {
}
+
+ ///
+ /// 添加新角色组
+ ///
+ /// 角色组名称
+ /// 角色组说明
+ /// 角色组信息
+ [HttpPost]
+ [ProducesResponseType(typeof(RoleGroup),200)]
+ public RoleGroup AddNew(string name,string description) {
+ if(name.IsNullOrEmpty()) {
+ throw new ArgumentNullException(nameof(name));
+ }
+ var qu = this.Db.RoleGroups.Where(m => m.Name == name);
+ if(qu.Any()) {
+ throw new Exception($"角色组{name}已经存在,不可以重复创建!");
+ }
+ var model = new RoleGroup {
+ Name = name,
+ Description = description,
+ };
+ this.Db.Entry(model).State = EntityState.Added;
+ this.Db.SaveChangesAsync().Wait();
+ return model;
+ }
+
+ ///
+ /// 查询角色组是否注册
+ ///
+ /// 角色组名称
+ /// 角色组信息
+ [HttpPost]
+ [ProducesResponseType(typeof(RoleGroup),200)]
+ public RoleGroup GetApps(string name) {
+ if(string.IsNullOrEmpty(name))
+ throw new ArgumentException("message",nameof(name));
+ var qu = this.Db.RoleGroups.Where(m => m.Name == name);
+ if(qu.Any()) {
+ return qu.First();
+ } else {
+ throw new Exception("没有找到该角色");
+ }
+ }
+
}
}
diff --git a/FAuth/Controllers/api/RoleGroup_RoleController.cs b/FAuth/Controllers/api/RoleGroup_RoleController.cs
new file mode 100644
index 0000000..3163520
--- /dev/null
+++ b/FAuth/Controllers/api/RoleGroup_RoleController.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Linq;
+using FAuth.DataBase.Tables;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+
+namespace FAuth.Controllers.api
+{
+ ///
+ /// 角色组角色对应
+ ///
+ public class RoleGroup_RoleController:ApiControllerBase
+ {
+ public RoleGroup_RoleController(ILogger logger,IServiceProvider service) : base(logger,service) {
+ }
+
+ ///
+ /// 绑定角色组和角色
+ ///
+ /// 角色组编号
+ /// 角色组
+ /// 是否成功
+ [HttpPost]
+ public bool Binding(int roleGroupId,int roleId) {
+ var rgQu = this.Db.RoleGroups.Where(m => m.Id == roleGroupId);
+ if(!rgQu.Any()) {
+ throw new Exception("没有找到指定的角色组");
+ }
+ var rQu = this.Db.Roles.Where(m => m.Id == roleId);
+ if(!rQu.Any()) {
+ throw new Exception("没有找到指定的角色");
+ }
+ var rgr = this.Db.RoleGroup_Roles.Where(m => m.RoleGroupId == roleGroupId && m.RoleId == roleId);
+ if(!rgr.Any()) {
+ this.Db.RoleGroup_Roles.Add(new RoleGroup_Role {
+ RoleGroupId = roleGroupId,
+ RoleId = roleId,
+ });
+ this.Db.SaveChangesAsync().Wait();
+ }
+ return true;
+ }
+
+ ///
+ /// 角色组角色解除绑定
+ ///
+ /// 角色组编号
+ /// 角色编号
+ /// 是否成功
+ [HttpPost]
+ public bool Unbind(int roleGroupId,int roleId) {
+ var rgQu = this.Db.RoleGroups.Where(m => m.Id == roleGroupId);
+ if(!rgQu.Any()) {
+ throw new Exception("没有找到指定的角色组");
+ }
+ var rQu = this.Db.Roles.Where(m => m.Id == roleId);
+ if(!rQu.Any()) {
+ throw new Exception("没有找到指定的角色");
+ }
+ var rgr = this.Db.RoleGroup_Roles.Where(m => m.RoleGroupId == roleGroupId && m.RoleId == roleId);
+ if(rgr.Any()) {
+ foreach(var item in rgr) {
+ this.Db.Entry(item).State = EntityState.Deleted;
+ }
+ this.Db.SaveChangesAsync().Wait();
+ }
+ return true;
+ }
+ }
+}
diff --git a/FAuth/Controllers/api/Role_UserController.cs b/FAuth/Controllers/api/Role_UserController.cs
new file mode 100644
index 0000000..01aa78b
--- /dev/null
+++ b/FAuth/Controllers/api/Role_UserController.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using FAuth.DataBase.Tables;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+
+namespace FAuth.Controllers.api
+{
+ ///
+ /// 角色用户绑定控制器
+ ///
+ public class Role_UserController:ApiControllerBase
+ {
+ public Role_UserController(ILogger logger,IServiceProvider service) : base(logger,service) {
+ }
+ ///
+ /// 绑定指定角色和用户
+ ///
+ /// 角色编号
+ /// 用户编号
+ /// 是否成功
+ [HttpPost]
+ public bool Binding(int roleId,int userId) {
+ var rQu = this.Db.Roles.Where(m => m.Id == roleId);
+ if(!rQu.Any()) {
+ throw new Exception("没有找到指定的角色");
+ }
+ var uQu = this.Db.Users.Where(m => m.Id == userId);
+ if(!uQu.Any()) {
+ throw new Exception("没有找到指定的用户");
+ }
+ var ruQu = this.Db.Role_Users.Where(m => m.RoleId == roleId && m.UserId == userId);
+ if(!ruQu.Any()) {
+ var model = new Role_User {
+ RoleId = roleId,
+ UserId = userId,
+ };
+ this.Db.Entry(model).State = EntityState.Added;
+ this.Db.SaveChangesAsync().Wait();
+ }
+ return true;
+ }
+ ///
+ /// 解除指定应用和角色组绑定
+ ///
+ ///
+ ///
+ /// 解绑是否成功
+ [HttpPost]
+ public bool Unbind(int roleId,int userId) {
+ var rQu = this.Db.Roles.Where(m => m.Id == roleId);
+ if(!rQu.Any()) {
+ throw new Exception("没有找到指定的角色");
+ }
+ var uQu = this.Db.Users.Where(m => m.Id == userId);
+ if(!uQu.Any()) {
+ throw new Exception("没有找到指定的用户");
+ }
+ var ruQu = this.Db.Role_Users.Where(m => m.RoleId == roleId && m.UserId == userId);
+ if(ruQu.Any()) {
+ foreach(var item in ruQu) {
+ this.Db.Entry(item).State = EntityState.Deleted;
+ }
+ this.Db.SaveChangesAsync().Wait();
+ }
+ return true;
+ }
+ }
+}