UserRoleController.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Bowin.Common.ServiceToken.Permission;
  6. using Bowin.Common.WebModels;
  7. using YLShipBuildLandMap.Entity;
  8. using YLShipBuildLandMap.Entity.ViewModel;
  9. using YLShipBuildLandMap.Entity.ViewModel.SystemSetting;
  10. using YLShipBuildLandMap.Services.SystemSetting;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.AspNetCore.Mvc;
  14. using Newtonsoft.Json.Linq;
  15. namespace YLShipBuildLandMap.Web.Controllers.SystemSetting
  16. {
  17. [Route("api/systemsetting/[controller]/[action]")]
  18. [ApiController]
  19. [Authorize]
  20. public class UserRoleController : ControllerBase
  21. {
  22. private IUserRoleService UserRoleService { get; set; }
  23. public UserRoleController(IUserRoleService userRoleService)
  24. {
  25. UserRoleService = userRoleService;
  26. }
  27. [HttpPost]
  28. [FunctionCode("9902")]
  29. public ResultMessage GetUserListByRole([FromBody] dynamic inputObj)
  30. {
  31. try
  32. {
  33. Guid? roleID = inputObj.roleID;
  34. string name = inputObj.name;
  35. int? pageIndex = inputObj.pageIndex;
  36. int? pageSize = inputObj.pageSize;
  37. var userList = UserRoleService.GetUserViewListByRole(roleID, name, pageIndex, pageSize);
  38. return ResultMessage.Success(userList);
  39. }
  40. catch (Exception ex)
  41. {
  42. return ResultMessage.GetError(ex.Message);
  43. }
  44. }
  45. [HttpPost]
  46. [FunctionCode("990201")]
  47. public async Task<ResultMessage> SaveUserRoleList([FromBody] dynamic inputObj)
  48. {
  49. try
  50. {
  51. Guid? roleId = inputObj.roleId;
  52. List<Guid> userIds = inputObj.userIds.ToObject<List<Guid>>();
  53. await UserRoleService.SaveUserRoleList(roleId, userIds);
  54. return ResultMessage.Success();
  55. }
  56. catch (Exception ex)
  57. {
  58. return ResultMessage.GetError(ex.Message);
  59. }
  60. }
  61. [HttpPost]
  62. [FunctionCode("990203")]
  63. public async Task<ResultMessage> DeleteUserRole([FromBody] dynamic inputObj)
  64. {
  65. try
  66. {
  67. Guid UserId = inputObj.userId;
  68. Guid RoleId = inputObj.roleId;
  69. await UserRoleService.DeleteUserRole(UserId, RoleId);
  70. return ResultMessage.Success();
  71. }
  72. catch (Exception ex)
  73. {
  74. return ResultMessage.GetError(ex.Message);
  75. }
  76. }
  77. }
  78. }