//XML, read UtilMenuItem GetMenuItemFromXElement(XElement element, List <UtilMenuItem> items) { UtilMenuItem obj = new UtilMenuItem(); obj.Link = ReadAttribute(element, "link"); obj.Role = ReadAttribute(element, "role"); obj.Permission = ReadAttribute(element, "permission"); obj.Text = ReadAttribute(element, "text"); obj.Title = ReadAttribute(element, "title"); obj.CssClass = ReadAttribute(element, "cssclass"); obj.IsParentClickable = ReadAttribute(element, "isParentClickable"); if (element.IsEmpty) { return(obj); } else { obj.SubMenuItems = new List <UtilMenuItem>(); IEnumerable <XElement> eles = from e in element.Elements("menuitem") select e; foreach (var el in eles) { obj.SubMenuItems.Add(GetMenuItemFromXElement(el, obj.SubMenuItems)); } return(obj); } }
bool HasAccess(UtilMenuItem item) { if (string.IsNullOrEmpty(item.Role)) { return(true); } string[] splitChar = new string[1] { "," }; string[] roles = item.Role.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); string[] permission = item.Permission.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (roles.Length > 0) { if (!roles.Contains(_loginUserRole)) { return(false); } } if (permission.Length > 0) { if (_permissions != null) { //Check permissions for other users. foreach (var perm in permission) { try { if (_permissions.Where(x => x.Key == perm && x.Value == true).Count() == 0) { return(false); } } catch { //empty on purpose } } } } return(true); }
UtilMenuItem GetMenuItems(UtilMenuItem item, StringBuilder sb, string idParentA) { if (item.SubMenuItems == null) { if (HasAccess(item)) { sb.Append("<li title=\"" + item.Title + "\" class=\"" + item.CssClass + "\" >"); sb.Append("<a class=\"fnClsMenuLink Ajax\" href=\"" + item.Link + "\" " + (string.IsNullOrEmpty(idParentA) ? "" : "parent='" + idParentA + "'") + ">" + item.Text + "</a>"); sb.Append("</li>"); } return(item); } else { string id = Guid.NewGuid().ToString("n"); if (HasAccess(item)) { idParentA = Guid.NewGuid().ToString("n"); sb.Append("<li class=\"LiSubMenu " + item.CssClass + "\" title=\"" + item.Title + "\" rel=\"" + id + "\" >"); if (!string.IsNullOrEmpty(item.IsParentClickable) && Convert.ToBoolean(item.IsParentClickable)) { sb.Append("<a id='" + idParentA + "' href=\"" + item.Link + "\" " + (string.IsNullOrEmpty(idParentA) ? "" : "parent='" + idParentA + "'") + ">" + item.Text + "</a>"); } else { sb.Append("<a id='" + idParentA + "' href=\"#\" >" + item.Text + "</a>"); } sb.Append("<ul id=\"" + id + "\" style=\"display:none\" >"); foreach (var itm in item.SubMenuItems) { UtilMenuItem mi = GetMenuItems(itm, sb, idParentA); } sb.Append("</ul>"); sb.Append("</li>"); } return(item); } }
string GetToUlLi() { StringBuilder sb = new StringBuilder(); sb.Append("<ul id=\"" + _menuUlID + "\" class=\"MenuItems" + this._menuType.ToString() + "\">"); if (!string.IsNullOrEmpty(this._title)) { sb.Append("<li class=\"Title\" >"); sb.Append(this._title); sb.Append("</li>"); } if (_items != null) { foreach (var item in _items) { UtilMenuItem mi = GetMenuItems(item, sb, string.Empty); } } sb.Append("</ul>"); return(sb.ToString()); }
//XML, read UtilMenuItem GetMenuItemFromXElement(XElement element, List<UtilMenuItem> items) { UtilMenuItem obj = new UtilMenuItem(); obj.Link = ReadAttribute(element, "link"); obj.Role = ReadAttribute(element, "role"); obj.Permission = ReadAttribute(element, "permission"); obj.Text = ReadAttribute(element, "text"); obj.Title = ReadAttribute(element, "title"); obj.CssClass = ReadAttribute(element, "cssclass"); obj.IsParentClickable = ReadAttribute(element, "isParentClickable"); if (element.IsEmpty) { return obj; } else { obj.SubMenuItems = new List<UtilMenuItem>(); IEnumerable<XElement> eles = from e in element.Elements("menuitem") select e; foreach (var el in eles) { obj.SubMenuItems.Add(GetMenuItemFromXElement(el, obj.SubMenuItems)); } return obj; } }
bool HasAccess(UtilMenuItem item) { if (string.IsNullOrEmpty(item.Role)) return true; string[] splitChar = new string[1] { "," }; string[] roles = item.Role.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); string[] permission = item.Permission.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (roles.Length > 0) { if (!roles.Contains(_loginUserRole)) return false; } if (permission.Length > 0) { if (_permissions != null) { //Check permissions for other users. foreach (var perm in permission) { try { if (_permissions.Where(x => x.Key == perm && x.Value == true).Count() == 0) return false; } catch { //empty on purpose } } } } return true; }
UtilMenuItem GetMenuItems(UtilMenuItem item, StringBuilder sb, string idParentA) { if (item.SubMenuItems == null) { if (HasAccess(item)) { sb.Append("<li title=\"" + item.Title + "\" class=\"" + item.CssClass + "\" >"); sb.Append("<a class=\"fnClsMenuLink Ajax\" href=\"" + item.Link + "\" " + (string.IsNullOrEmpty(idParentA) ? "" : "parent='" + idParentA + "'") + ">" + item.Text + "</a>"); sb.Append("</li>"); } return item; } else { string id = Guid.NewGuid().ToString("n"); if (HasAccess(item)) { idParentA = Guid.NewGuid().ToString("n"); sb.Append("<li class=\"LiSubMenu " + item.CssClass + "\" title=\"" + item.Title + "\" rel=\"" + id + "\" >"); if (!string.IsNullOrEmpty(item.IsParentClickable) && Convert.ToBoolean(item.IsParentClickable)) sb.Append("<a id='" + idParentA + "' href=\"" + item.Link + "\" " + (string.IsNullOrEmpty(idParentA) ? "" : "parent='" + idParentA + "'") + ">" + item.Text + "</a>"); else sb.Append("<a id='" + idParentA + "' href=\"#\" >" + item.Text + "</a>"); sb.Append("<ul id=\"" + id + "\" style=\"display:none\" >"); foreach (var itm in item.SubMenuItems) { UtilMenuItem mi = GetMenuItems(itm, sb, idParentA); } sb.Append("</ul>"); sb.Append("</li>"); } return item; } }