MenuServices.cs 1.7 KB

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