using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Yi.Framework.Common.Models; using Yi.Framework.DTOModel; using Yi.Framework.Interface; using Yi.Framework.Model.Models; using Yi.Framework.WebCore; namespace Yi.Framework.ApiMicroservice.Controllers { [Route("api/[controller]/[action]")] [ApiController] [Authorize] public class RoleController : ControllerBase { private IRoleService _roleService; public RoleController(IRoleService roleService) { _roleService = roleService; } [HttpGet] public async Task GetRole() { return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync()); } /// /// 更 /// /// /// [HttpPut] public async Task UpdateRole(role _role) { await _roleService.UpdateAsync(_role); return Result.Success(); } /// /// 删 /// /// /// [HttpDelete] public async Task DelListRole(List _ids) { await _roleService.DelListByUpdateAsync(_ids); return Result.Success(); } /// /// 增 /// /// /// [HttpPost] public async Task AddRole(role _role) { await _roleService.AddAsync(_role); return Result.Success(); } /// /// 根据用户id得到该用户有哪些角色 /// 用于显示用户详情中的角色说明 /// /// [HttpGet] public async Task GetRolesByUserId(int userId) { return Result.Success().SetData(await _roleService.GetRolesByUserId(userId)); } /// /// 给角色设置菜单,多个角色与多个菜单,让每一个角色都设置,ids1为角色,ids2为菜单 /// 用于设置角色 /// /// /// [HttpPost] public async Task SetMenuByRole(IdsListDto idsListDto) { await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1); return Result.Success(); } /// /// 用于给角色设置菜单的时候,点击一个角色,显示这个角色拥有的并列的菜单 /// /// /// [HttpGet] public async Task GetTopMenusByRoleId(int roleId) { return Result.Success().SetData(await _roleService.GetTopMenusByRoleId(roleId) ); ; } } }