2020-04-14 16:44:05 +08:00
|
|
|
|
using System;
|
2020-04-15 17:54:33 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Falcon.Extend;
|
|
|
|
|
using FAuth.DataBase.Tables;
|
2020-05-06 15:57:09 +08:00
|
|
|
|
using FAuth.Extensions;
|
2020-04-15 17:54:33 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2020-04-14 16:44:05 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace FAuth.Controllers.api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角色组控制器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RoleGroupController:ApiControllerBase<RoleGroupController>
|
|
|
|
|
{
|
|
|
|
|
public RoleGroupController(ILogger<RoleGroupController> logger,IServiceProvider service) : base(logger,service) {
|
|
|
|
|
}
|
2020-04-15 17:54:33 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加新角色组
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">角色组名称</param>
|
|
|
|
|
/// <param name="description">角色组说明</param>
|
|
|
|
|
/// <returns>角色组信息</returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(RoleGroup),200)]
|
2020-05-06 16:02:54 +08:00
|
|
|
|
public RoleGroup AddNewGroup(string name,string description) {
|
2020-04-15 17:54:33 +08:00
|
|
|
|
if(name.IsNullOrEmpty()) {
|
2020-05-06 15:57:09 +08:00
|
|
|
|
throw new ApiArgumentNullException(nameof(name));
|
2020-04-15 17:54:33 +08:00
|
|
|
|
}
|
|
|
|
|
var qu = this.Db.RoleGroups.Where(m => m.Name == name);
|
|
|
|
|
if(qu.Any()) {
|
2020-05-06 15:57:09 +08:00
|
|
|
|
throw new ApiException($"角色组{name}已经存在,不可以重复创建!");
|
2020-04-15 17:54:33 +08:00
|
|
|
|
}
|
|
|
|
|
var model = new RoleGroup {
|
|
|
|
|
Name = name,
|
|
|
|
|
Description = description,
|
|
|
|
|
};
|
|
|
|
|
this.Db.Entry(model).State = EntityState.Added;
|
|
|
|
|
this.Db.SaveChangesAsync().Wait();
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询角色组是否注册
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">角色组名称</param>
|
|
|
|
|
/// <returns>角色组信息</returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(RoleGroup),200)]
|
2020-05-06 16:02:54 +08:00
|
|
|
|
public RoleGroup GetRoleGroups(string name) {
|
2020-04-15 17:54:33 +08:00
|
|
|
|
if(string.IsNullOrEmpty(name))
|
2020-05-06 15:57:09 +08:00
|
|
|
|
throw new ApiArgumentNullException(nameof(name));
|
2020-04-15 17:54:33 +08:00
|
|
|
|
var qu = this.Db.RoleGroups.Where(m => m.Name == name);
|
|
|
|
|
if(qu.Any()) {
|
|
|
|
|
return qu.First();
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("没有找到该角色");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-14 16:44:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|