SysRoleGroupService.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Furion.DatabaseAccessor.Extensions;
  2. using YBEE.EQM.Core;
  3. namespace YBEE.EQM.Application
  4. {
  5. /// <summary>
  6. /// 角色组服务
  7. /// </summary>
  8. public class SysRoleGroupService : ISysRoleGroupService, ITransient
  9. {
  10. private readonly IRepository<SysRoleGroup> _roleGroupRep;
  11. public SysRoleGroupService(IRepository<SysRoleGroup> roleGroupRep)
  12. {
  13. _roleGroupRep = roleGroupRep;
  14. }
  15. /// <summary>
  16. /// 添加角色组
  17. /// </summary>
  18. /// <param name="input"></param>
  19. /// <returns></returns>
  20. public async Task<int> Add(AddSysRoleGroupInput input)
  21. {
  22. var isExist = await _roleGroupRep.DetachedEntities.AnyAsync(u => u.Name == input.Name);
  23. if (isExist)
  24. {
  25. throw Oops.Oh(ErrorCode.E2004);
  26. }
  27. var roleGroup = input.Adapt<SysRoleGroup>();
  28. await roleGroup.InsertNowAsync();
  29. return roleGroup.Id;
  30. }
  31. /// <summary>
  32. /// 更新角色组
  33. /// </summary>
  34. /// <param name="input"></param>
  35. /// <returns></returns>
  36. public async Task Update(UpdateSysRoleGroupInput input)
  37. {
  38. var rg = await _roleGroupRep.FindOrDefaultAsync(input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  39. if (await _roleGroupRep.AnyAsync(t => t.Id != input.Id && t.Name.ToLower() == input.Name.ToLower()))
  40. {
  41. throw Oops.Oh(ErrorCode.E2004);
  42. }
  43. rg.Name = input.Name;
  44. rg.Remark = input.Remark;
  45. await _roleGroupRep.SaveNowAsync();
  46. }
  47. /// <summary>
  48. /// 删除角色组
  49. /// </summary>
  50. /// <param name="input"></param>
  51. /// <returns></returns>
  52. public async Task Del(DeleteSysRoleGroupInput input)
  53. {
  54. var rg = await _roleGroupRep.FindOrDefaultAsync(input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  55. await _roleGroupRep.DeleteAsync(rg);
  56. }
  57. /// <summary>
  58. /// 获取所有角色组列表
  59. /// </summary>
  60. /// <returns></returns>
  61. public async Task<List<SysRoleGroupOutput>> GetAllList()
  62. {
  63. var items = await _roleGroupRep.DetachedEntities.Where(u => u.IsDeleted == false)
  64. .ProjectToType<SysRoleGroupOutput>()
  65. .ToListAsync();
  66. return items;
  67. }
  68. }
  69. }