public JsonResult GetTreeData(string userName = null) { if (string.IsNullOrEmpty(userName)) { userName = User.Identity.Name; } Dictionary <string, object> param = new Dictionary <string, object>(); param.Add("UserName", userName); IList <TPrivilege> privileges = _tPrivilegeRepository.FindAll(param); var menus = from menu in _mMenuRepository.GetAll() where menu.MenuParent == null select new JsTreeModel() { data = menu.MenuName, attributes = new JsTreeAttribute { id = menu.Id, selected = HasAccess(menu, privileges), link = Url.Content(menu.MenuLink) }, children = (from child in menu.MenuChildren select new JsTreeModel() { data = child.MenuName, attributes = new JsTreeAttribute { id = child.Id, selected = HasAccess(child, privileges), link = Url.Content(child.MenuLink) } }).ToArray() }; return(Json(menus)); }
public static PrivilegeViewModel Create(string userName, IMMenuRepository mMenuRepository, ITPrivilegeRepository tPrivilegeRepository) { var viewModel = new PrivilegeViewModel(); Dictionary <string, object> param = new Dictionary <string, object>(); param.Add("UserName", userName); IList <TPrivilege> privileges = tPrivilegeRepository.FindAll(param); var menus = from menu in mMenuRepository.GetAll() where menu.MenuParent == null select new PrivilegeViewModel() { Menu = menu, HasAccess = CheckAccess(menu, privileges), children = (from child in menu.MenuChildren select new PrivilegeViewModel() { Menu = child, HasAccess = CheckAccess(menu, privileges), }).ToArray() }; return(viewModel); }