public SpaNavigationModel(IPublishedContent content, int levels, bool navContext = false) { if (content == null) { return; } List <IPublishedContent> path = new List <IPublishedContent>(); // fill path if (navContext) { string[] _path = content.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); path = _path.Where(x => int.Parse(x) > 0).Select(x => UmbracoContext.Current.ContentCache.GetById(int.Parse(x))).Where(x => x.IsVisible()).ToList(); // context Context = GetNavContext(path); } // children Children = content.Children().Where(x => x.IsVisible()).Select(x => NavItem.GetItem(x, levels)).ToList(); }
public static NavItem GetItem(IPublishedContent content, int levels = 1, int levelcount = 1) { if (content == null) { return(null); } IPublishedContent[] children = content.Children(x => x.TemplateId > 0 && x.IsVisible()).ToArray(); CultureInfo culture = content.GetCulture(); return(new NavItem { Id = content.Id, Title = content.GetSpaTitle(), Url = content.Url, ParentId = content.Parent != null ? content.Parent.Id : -1, Template = content.GetTemplateAlias(), Culture = culture.Name, HasChildren = children.Any(), IsVisible = !content.HasProperty(Constants.SkyConstants.Properties.UmbracoNaviHide) || !content.GetPropertyValue <bool>(Constants.SkyConstants.Properties.UmbracoNaviHide), Children = children.Any() && levels > levelcount?children.Select(x => NavItem.GetItem(x, levels)).ToArray() : new NavItem[0], }); }