MenuService.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Bowin.Common.Linq;
  2. using YLShipBuildLandMap.Entity;
  3. using YLShipBuildLandMap.Entity.ViewModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Linq.Expressions;
  8. using System.Text;
  9. namespace YLShipBuildLandMap.Services.SystemSetting
  10. {
  11. public class MenuService : IMenuService
  12. {
  13. private YLShipBuildLandMapContext DbContext { get; set; }
  14. public MenuService(YLShipBuildLandMapContext dbContext)
  15. {
  16. DbContext = dbContext;
  17. }
  18. private IQueryable<SysMenu> GetMenuByUser(
  19. Expression<Func<SysMenu, bool>> menuDefineExp,
  20. Expression<Func<SysUser, bool>> userExp)
  21. {
  22. var userFunc = userExp;
  23. var menuDefineFunc = menuDefineExp;
  24. var iqResult = (
  25. from m in this.DbContext.SysMenu.Where(menuDefineExp)
  26. where m.FunctionCode == null || (
  27. from u in this.DbContext.SysUser.Where(userExp)
  28. from r in u.SysUserSysRole
  29. from f in r.Role.SysRoleSysFunctionCode
  30. where f.FunctionCode == m.FunctionCode
  31. select 1
  32. ).Any()
  33. select m
  34. );
  35. return iqResult.OrderBy(x => x.OrderNo).ThenBy(x => x.MenuNo);
  36. }
  37. public List<SysMenu> GetMenuByUserID(Guid userID)
  38. {
  39. Expression<Func<SysMenu, bool>> menuDefineExp = (x => x.RecordStatus >= 1);
  40. Expression<Func<SysUser, bool>> userExp = (x => x.UserId == userID);
  41. return GetMenuByUser(menuDefineExp, userExp).ToList();
  42. }
  43. }
  44. }