using System; using System.Collections.Generic; using Infrastructure; using Microsoft.AspNetCore.Mvc; using OpenAuth.App; using OpenAuth.App.Request; using OpenAuth.App.Response; using OpenAuth.Repository.Domain; namespace OpenAuth.WebApi.Controllers { /// /// 表单操作 /// [Route("api/[controller]/[action]")] [ApiController] public class RolesController : ControllerBase { private readonly RoleApp _app; private readonly RevelanceManagerApp _revelanceManagerApp; public RolesController(RevelanceManagerApp revelanceManagerApp, RoleApp app) { _revelanceManagerApp = revelanceManagerApp; _app = app; } [HttpGet] public Response Get(string id) { var result = new Response(); try { result.Result = _app.Get(id); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 添加角色,如果当前登录用户不是System,则直接把新角色分配给当前登录用户 /// [HttpPost] public Response Add(RoleView obj) { var result = new Response(); try { _app.Add(obj); result.Result = obj; } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 更新角色属性 /// /// /// [HttpPost] public Response Update(RoleView obj) { var result = new Response(); try { _app.Update(obj); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 加载列表 /// [HttpGet] public Response> Load([FromQuery]QueryRoleListReq request) { var result = new Response>(); try { result.Result = _app.Load(request); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 加载用户的角色 /// [HttpGet] public Response> LoadForUser(string userId) { var result = new Response>(); try { result.Result = _revelanceManagerApp.Get(Define.USERROLE, true, userId); } catch (Exception e) { result.Code = 500; result.Message = e.InnerException?.Message ?? e.Message; } return result; } [HttpPost] public Response Delete([FromBody]string[] ids) { var result = new Response(); try { _app.Delete(ids); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } } }