using System; using System.Linq; using Falcon.Extend; using FAuth.DataBase.Tables; using FAuth.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; namespace FAuth.Controllers.api { /// /// 角色组控制器 /// public class RoleGroupController:ApiControllerBase { 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 ApiArgumentNullException(nameof(name)); } var qu = this.Db.RoleGroups.Where(m => m.Name == name); if(qu.Any()) { throw new ApiException($"角色组{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 ApiArgumentNullException(nameof(name)); var qu = this.Db.RoleGroups.Where(m => m.Name == name); if(qu.Any()) { return qu.First(); } else { throw new Exception("没有找到该角色"); } } } }