RoleService.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using GxPress.Repository.Interface.SystemRoleMenus;
  2. using GxPress.Service.Interface.Role;
  3. using GxPress.Repository.Interface.SystemRole;
  4. using GxPress.Repository.Interface.Menus;
  5. using System.Threading.Tasks;
  6. using GxPress.Request.Role;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. namespace GxPress.Service.Implement.Role
  10. {
  11. public class RoleService : IRoleService
  12. {
  13. private readonly ISystemRoleMenusRepository systemRoleMenusRepository;
  14. private readonly IMenusRepository menusRepository;
  15. private readonly ISystemRoleRepository systemRoleRepository;
  16. public RoleService(ISystemRoleMenusRepository systemRoleMenusRepository, IMenusRepository menusRepository, ISystemRoleRepository systemRoleRepository)
  17. {
  18. this.systemRoleRepository = systemRoleRepository;
  19. this.systemRoleMenusRepository = systemRoleMenusRepository;
  20. this.menusRepository = menusRepository;
  21. }
  22. /// <summary>
  23. /// 添加权限菜单关联
  24. /// </summary>
  25. /// <param name="models"></param>
  26. /// <returns></returns>
  27. public async Task<bool> InsertSystemRoleMenusAsync(SystemRoleMenusInRequest models)
  28. {
  29. return await systemRoleMenusRepository.InsertAsync(models);
  30. }
  31. /// <summary>
  32. /// 添加权限
  33. /// </summary>
  34. /// <param name="models"></param>
  35. /// <returns></returns>
  36. public async Task<bool> InsertSystemRoleAsync(Entity.SystemRole.SystemRole model)
  37. {
  38. return await systemRoleRepository.InsertAsync(model) > 0;
  39. }
  40. /// <summary>
  41. /// 修改权限
  42. /// </summary>
  43. /// <param name="model"></param>
  44. /// <returns></returns>
  45. public async Task<bool> UpdateSystemRoleAsync(Entity.SystemRole.SystemRole model)
  46. {
  47. return await systemRoleRepository.UpdateAsync(model);
  48. }
  49. /// <summary>
  50. /// 删除权限
  51. /// </summary>
  52. /// <param name="id"></param>
  53. /// <returns></returns>
  54. public async Task<bool> DeleteSystemRoleAsync(int id)
  55. {
  56. return await systemRoleRepository.DeleteAsync(id);
  57. }
  58. /// <summary>
  59. /// 添加菜单
  60. /// </summary>
  61. /// <param name="models"></param>
  62. /// <returns></returns>
  63. public async Task<bool> InsertMenusAsync(Entity.Menus.Menus model)
  64. {
  65. return await menusRepository.InsertAsync(model) > 0;
  66. }
  67. /// <summary>
  68. /// 修改菜单
  69. /// </summary>
  70. /// <param name="model"></param>
  71. /// <returns></returns>
  72. public async Task<bool> UpdateMenusAsync(Entity.Menus.Menus model)
  73. {
  74. return await menusRepository.UpdateAsync(model);
  75. }
  76. /// <summary>
  77. /// 删除菜单
  78. /// </summary>
  79. /// <param name="id"></param>
  80. /// <returns></returns>
  81. public async Task<bool> DeleteMenusAsync(int id)
  82. {
  83. return await menusRepository.DeleteAsync(id);
  84. }
  85. /// <summary>
  86. /// 根据权限ID获取菜单
  87. /// </summary>
  88. /// <param name="roleId"></param>
  89. /// <returns></returns>
  90. public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync(int roleId)
  91. {
  92. //获取
  93. var models = await systemRoleMenusRepository.GetAllAsync(roleId);
  94. return await menusRepository.GetAllAsync(models.Select(n => n.Id).ToList());
  95. }
  96. /// <summary>
  97. /// 获取所有菜单
  98. /// </summary>
  99. /// <param name="roleId"></param>
  100. /// <returns></returns>
  101. public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync()
  102. {
  103. return await menusRepository.GetAllAsync();
  104. }
  105. }
  106. }