2021-10-13 23:08:42 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Yi.Framework.Common.Models;
|
2021-10-14 13:15:00 +08:00
|
|
|
|
using Yi.Framework.DTOModel;
|
2021-10-13 23:08:42 +08:00
|
|
|
|
using Yi.Framework.Interface;
|
|
|
|
|
|
using Yi.Framework.Model.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.ApiMicroservice.Controllers
|
|
|
|
|
|
{
|
2021-10-14 13:15:00 +08:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
2021-10-13 23:08:42 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
|
public class RoleController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private IRoleService _roleService;
|
|
|
|
|
|
public RoleController(IRoleService roleService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_roleService = roleService;
|
|
|
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
2021-10-14 13:15:00 +08:00
|
|
|
|
public async Task<Result> GetRole()
|
2021-10-13 23:08:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
return Result.Success().SetData(await _roleService.GetAllEntitiesTrueAsync());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="_role"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPut]
|
|
|
|
|
|
public async Task<Result> UpdateRole(role _role)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _roleService.UpdateAsync(_role);
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="_ids"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
|
public async Task<Result> DelListRole(List<int> _ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _roleService.DelListByUpdateAsync(_ids);
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="_role"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<Result> AddRole(role _role)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _roleService.AddAsync(_role);
|
|
|
|
|
|
return Result.Success();
|
|
|
|
|
|
}
|
2021-10-14 13:15:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 给角色设置菜单,多个角色与多个菜单,让每一个角色都设置,ids1为角色,ids2为菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="idsListDto"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
public async Task<Result> SetMenuByRole(IdsListDto<int> idsListDto)
|
2021-10-15 14:45:16 +08:00
|
|
|
|
{
|
2021-10-17 23:17:07 +08:00
|
|
|
|
await _roleService.SetMenusByRolesId(idsListDto.ids2, idsListDto.ids1);
|
2021-10-15 14:45:16 +08:00
|
|
|
|
return Result.Success();
|
2021-10-14 13:15:00 +08:00
|
|
|
|
}
|
2021-10-18 18:49:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-13 23:08:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|