SysMenuRepository.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using ERP.Core.Entities;
  2. using ERP.Framework.WebApi;
  3. namespace ERP.Core.Repositorys
  4. {
  5. public class SysMenuRepository : BaseRepository<SysMenu, CoreDbContext>
  6. {
  7. public SysMenuRepository(CoreDbContext context) : base(context)
  8. {
  9. }
  10. public List<SysMenu> SelectMenuListByUserId(long userId)
  11. {
  12. var q = from m in Context.Set<SysMenu>()
  13. join rm in Context.Set<SysRoleMenu>() on m.Id equals rm.RoleId
  14. join r in Context.Set<SysRole>() on rm.RoleId equals r.Id
  15. join ru in Context.Set<SysUserRole>() on r.Id equals ru.RoleId
  16. join u in Context.Set<SysUser>() on ru.UserId equals u.Id
  17. where u.Id == userId
  18. select m;
  19. return q.ToList();
  20. }
  21. public List<string> SelectPermissionsByRoleIds(List<long> roleIds)
  22. {
  23. var q = from rm in Context.Set<SysRoleMenu>()
  24. join m in Context.Set<SysMenu>() on rm.MenuId equals m.Id
  25. where roleIds.Contains(rm.RoleId)
  26. select m.Permission;
  27. return q.ToList();
  28. }
  29. }
  30. }