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 GetMenuByUserIDAndRoleID(Guid userID, Guid? roleID) { Expression> menuDefineExp = (x => x.RecordStatus >= (int)SYS_STATUS.USABLE); Expression> 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 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 ""; } } } }