123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Bowin.Common.ServiceToken.Permission;
- using Bowin.Common.WebModels;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
- using YLShipBuildLandMap.Services.SystemSetting;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json.Linq;
- namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
- {
- [Route("api/systemsetting/[controller]/[action]")]
- [ApiController]
- [Authorize]
- public class RoleController : ControllerBase
- {
- private IRoleService RoleService { get; set; }
- private IMenuService MenuService { get; set; }
- private IFunctionCodeService FunctionCodeService { get; set; }
- public RoleController(IRoleService roleService, IFunctionCodeService functionCodeService)
- {
- RoleService = roleService;
- FunctionCodeService = functionCodeService;
- }
- [HttpPost]
- public ResultMessage GetRolesForSelect([FromBody] dynamic inputObj)
- {
- try
- {
- string roleName = inputObj.roleName;
- int? pageIndex = inputObj.pageIndex;
- int? pageSize = inputObj.pageSize;
- return ResultMessage.Success(RoleService.GetRoleViewsForSelect(roleName, pageIndex, pageSize));
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("9902")]
- public ResultMessage GetRoleList([FromBody] dynamic inputObj)
- {
- try
- {
- string roleName = inputObj.roleName;
- int? pageIndex = inputObj.pageIndex;
- int? pageSize = inputObj.pageSize;
- var roleList = RoleService.GetRoleViewList(roleName, pageIndex, pageSize);
- return ResultMessage.Success(roleList);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("9902")]
- public ResultMessage GetRole([FromBody] dynamic inputObj)
- {
- try
- {
- Guid roleID = inputObj.roleID;
- var role = RoleService.GetRoleView(roleID);
- return ResultMessage.Success(role);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990201")]
- public async Task<ResultMessage> Add([FromBody] JObject inputObj)
- {
- try
- {
- RoleView role = inputObj["role"].ToObject<RoleView>();
- List<string> functionCodes = inputObj["functionCodes"].ToObject<List<string>>();
- RoleView result = RoleService.GetRoleViewByName(role.RoleName);
- if (result != null)
- {
- return ResultMessage.GetError("角色已存在");
- }
- role.RoleID = null;
- await RoleService.Save(role, functionCodes, LoginUser.Current.UserID);
- return ResultMessage.Success();
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990202")]
- public async Task<ResultMessage> Edit([FromBody] dynamic inputObj)
- {
- try
- {
- RoleView role = inputObj["role"].ToObject<RoleView>();
- List<string> functionCodes = inputObj["functionCodes"].ToObject<List<string>>();
- if (!role.RoleID.HasValue)
- {
- throw new Exception("实体ID不能为空。");
- }
- await RoleService.Save(role, functionCodes, LoginUser.Current.UserID);
- return ResultMessage.Success();
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990203")]
- public async Task<ResultMessage> Delete([FromBody] dynamic inputObj)
- {
- try
- {
- List<Guid> roleIDList = inputObj.roleIDs.ToObject<List<Guid>>();
- await RoleService.Delete(roleIDList);
-
- return ResultMessage.Success();
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990202")]
- public ResultMessage GetFunctionCodeList()
- {
- try
- {
- var functionCodeList = FunctionCodeService.GetFunctionCodeList();
- return ResultMessage.Success(functionCodeList);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- [HttpPost]
- [FunctionCode("990202")]
- public ResultMessage GetRoleFunctionCode([FromBody] dynamic inputObj)
- {
- try
- {
- Guid roleID = inputObj.roleID;
- List<String> roleFunctionCodeList = FunctionCodeService.GetRoleFunctionCode(roleID);
- return ResultMessage.Success(roleFunctionCodeList);
- }
- catch (Exception ex)
- {
- return ResultMessage.GetError(ex.Message);
- }
- }
- }
- }
|