123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using Bowin.Common.Linq;
- using EMIS.DataLogic.SystemDAL;
- using EMIS.Entities;
- using EMIS.ViewModel;
- namespace EMIS.CommonLogic.SystemServices
- {
- public class MenuServices : BaseServices, IMenuServices
- {
- public MenuDAL MenuDAL { get; set; }
- public IList<Sys_Menu> GetMenuByUserIDAndRoleID(Guid userID, Guid? roleID)
- {
- Expression<Func<Sys_Menu, bool>> menuDefineExp = (x => x.RecordStatus >= (int)SYS_STATUS.USABLE);
- Expression<Func<Sys_User, bool>> userExp = (x => x.UserID == userID);
- if (roleID.HasValue)
- {
- menuDefineExp = menuDefineExp.And(x => x.FunctionCode == null || x.Sys_FunctionCode.Sys_Role.Any(w => w.RoleID == roleID.Value));
- }
- return MenuDAL.GetMenuByUser(menuDefineExp, userExp).ToList();
- }
- public string GetFullMenuPath(string menuNo)
- {
- var menu = MenuDAL.MenuRepository.GetSingle(x => x.MenuNo == menuNo);
- var menuList = MenuDAL.MenuRepository.Entities.ToList();
- return this.GetParentMenuName(menu, menuList);
- }
- private string GetParentMenuName(Sys_Menu menu, IList<Sys_Menu> menuList)
- {
- if (menu != null)
- {
- if ((menu.ParentMenuNo ?? "") != "")
- {
- var parentMenu = menuList.Where(x => x.MenuNo == menu.ParentMenuNo).FirstOrDefault();
- return this.GetParentMenuName(parentMenu, menuList) + " -> " + menu.MenuName;
- }
- return menu.MenuName;
- }
- else
- {
- return "";
- }
- }
- }
- }
|