MenuServices.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using EMIS.DataLogic.SystemDAL;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.CommonLogic.SystemServices
  11. {
  12. public class MenuServices : BaseServices, IMenuServices
  13. {
  14. public MenuDAL MenuDAL { get; set; }
  15. public IList<Sys_Menu> GetMenuByUserIDAndRoleID(Guid userID, Guid? roleID)
  16. {
  17. Expression<Func<Sys_Menu, bool>> menuDefineExp = (x => x.RecordStatus >= (int)SYS_STATUS.USABLE);
  18. Expression<Func<Sys_User, bool>> userExp = (x => x.UserID == userID);
  19. if (roleID.HasValue)
  20. {
  21. menuDefineExp = menuDefineExp.And(x => x.FunctionCode == null || x.Sys_FunctionCode.Sys_Role.Any(w => w.RoleID == roleID.Value));
  22. }
  23. return MenuDAL.GetMenuByUser(menuDefineExp, userExp).ToList();
  24. }
  25. public string GetFullMenuPath(string menuNo)
  26. {
  27. var menu = MenuDAL.MenuRepository.GetSingle(x => x.MenuNo == menuNo);
  28. var menuList = MenuDAL.MenuRepository.Entities.ToList();
  29. return this.GetParentMenuName(menu, menuList);
  30. }
  31. private string GetParentMenuName(Sys_Menu menu, IList<Sys_Menu> menuList)
  32. {
  33. if (menu != null)
  34. {
  35. if ((menu.ParentMenuNo ?? "") != "")
  36. {
  37. var parentMenu = menuList.Where(x => x.MenuNo == menu.ParentMenuNo).FirstOrDefault();
  38. return this.GetParentMenuName(parentMenu, menuList) + " -> " + menu.MenuName;
  39. }
  40. return menu.MenuName;
  41. }
  42. else
  43. {
  44. return "";
  45. }
  46. }
  47. }
  48. }