ContextMenuDAL.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.Entities;
  7. using EMIS.ViewModel;
  8. namespace EMIS.DataLogic.SystemDAL
  9. {
  10. public class ContextMenuDAL
  11. {
  12. public RoleRepository RoleRepository { get; set; }
  13. public UserRepository UserRepository { get; set; }
  14. public ContextMenuRepository ContextMenuRepository { get; set; }
  15. /// <summary>
  16. /// 根据对应的条件查询相应页面的权限信息
  17. /// </summary>
  18. /// <param name="menuNo"></param>
  19. /// <param name="formClass"></param>
  20. /// <param name="userID"></param>
  21. /// <param name="roleID"></param>
  22. /// <returns></returns>
  23. public IQueryable<Sys_ContextMenu> GetContextMenuListByUserAndRoleID(string menuNo, string formClass, Guid userID, Guid? roleID)
  24. {
  25. var query = from cm in ContextMenuRepository.GetList(x => x.RecordStatus >= (int)SYS_STATUS.USABLE)
  26. from tr in cm.Sys_FunctionCode.Sys_Role.Where(x => x.RecordStatus >= (int)SYS_STATUS.USABLE).DefaultIfEmpty()
  27. from ur in tr.Sys_User.DefaultIfEmpty()
  28. where
  29. (cm.FunctionCode == null || !cm.IsNeedPrivilege || (((ur != null) ? ur.UserID : Guid.Empty) == userID
  30. && (roleID == null || tr.RoleID == roleID)))
  31. && cm.MenuNo == menuNo
  32. && cm.FormClass == formClass
  33. select cm;
  34. return query.Distinct();
  35. }
  36. }
  37. }