Uri QualifyUri(string path, QueryString queryString = null) { if (queryString != null && queryString.Count > 0) { Uri uri = linkResolver.Resolve(path); NameValueCollection currentQueryStrings = HttpUtility.ParseQueryString(uri.Query); foreach (var pair in queryString) { currentQueryStrings.Set(pair.Key, pair.Value.ToString()); } path = string.Concat(uri.AbsolutePath, "?", currentQueryStrings); } return(linkResolver.Resolve(path)); }
public ActionResult Edit(int id) { var topic = _topicService.GetTopicById(id); if (topic == null) { return(RedirectToAction("List")); } var model = topic.ToModel(); model.Url = GetTopicUrl(topic); model.WidgetZone = topic.WidgetZone.SplitSafe(","); PrepareStoresMappingModel(model, topic, false); PrepareAclModel(model, topic, false); AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.ShortTitle = topic.GetLocalized(x => x.ShortTitle, languageId, false, false); locale.Title = topic.GetLocalized(x => x.Title, languageId, false, false); locale.Intro = topic.GetLocalized(x => x.Intro, languageId, false, false); locale.Body = topic.GetLocalized(x => x.Body, languageId, false, false); locale.MetaKeywords = topic.GetLocalized(x => x.MetaKeywords, languageId, false, false); locale.MetaDescription = topic.GetLocalized(x => x.MetaDescription, languageId, false, false); locale.MetaTitle = topic.GetLocalized(x => x.MetaTitle, languageId, false, false); locale.SeName = topic.GetSeName(languageId, false, false); }); // Get menu links. IPagedList <MenuRecord> menus = null; var pageIndex = 0; do { menus = _menuStorage.GetAllMenus(null, 0, true, pageIndex++, 500); foreach (var menu in menus) { foreach (var item in menu.Items.Where(x => x.ProviderName != null && x.ProviderName == "entity")) { var link = _linkResolver.Resolve(item.Model); if (link.Type == LinkType.Topic && link.Id == topic.Id) { var url = Url.Action("EditItem", "Menu", new { id = item.Id, area = "Admin" }); var label = string.Concat( menu.Title.NullEmpty() ?? menu.SystemName.NullEmpty() ?? "".NaIfEmpty(), " » ", item.Title.NullEmpty() ?? link.Label.NullEmpty() ?? "".NaIfEmpty()); model.MenuLinks[url] = label; } } } }while (menus.HasNextPage); return(View(model)); }
protected override void ApplyLink(MenuItemProviderRequest request, TreeNode <MenuItem> node) { // Always resolve against current store, current customer and working language. var result = _linkResolver.Resolve(request.Entity.Model); var item = node.Value; item.Url = result.Link; item.ImageId = result.PictureId; if (item.Text.IsEmpty()) { item.Text = result.Label; } switch (result.Type) { case LinkType.Product: case LinkType.Category: case LinkType.Manufacturer: case LinkType.Topic: if (request.IsEditMode) { // Info: node.Value.EntityId is MenuItemRecord.Id for editing MenuItemRecord. } else { item.EntityId = result.Id; item.EntityName = result.Type.ToString(); } break; } if (request.IsEditMode) { var info = result.Type.GetLinkTypeInfo(); item.Summary = T(info.ResKey); item.Icon = info.Icon; if (item.Url.IsEmpty()) { item.Text = null; item.ResKey = "Admin.ContentManagement.Menus.SpecifyLinkTarget"; } } else { // For edit mode, only apply MenuItemRecord.Published. item.Visible = result.Status == LinkStatus.Ok; } }
private TreeNode <MenuItem> ConvertNode( MenuItemProviderRequest request, TreeNode <ICategoryNode> categoryNode, IDictionary <int, PictureInfo> allPictureInfos, ref int randomId) { var node = categoryNode.Value; var name = node.Id > 0 ? node.GetLocalized(x => x.Name) : null; var menuItem = new MenuItem { Id = randomId++.ToString(), EntityId = node.Id, EntityName = nameof(Category), Text = name?.Value ?? node.Name, Rtl = name?.CurrentLanguage?.Rtl ?? false, BadgeText = node.Id > 0 ? node.GetLocalized(x => x.BadgeText) : null, BadgeStyle = (BadgeStyle)node.BadgeStyle, RouteName = node.Id > 0 ? "Category" : "HomePage", }; // Handle external link if (node.ExternalLink.HasValue()) { var link = _linkResolver.Resolve(node.ExternalLink); if (link.Status == LinkStatus.Ok) { menuItem.Url = link.Link; } } if (menuItem.Url.IsEmpty()) { if (node.Id > 0) { menuItem.RouteName = "Category"; menuItem.RouteValues.Add("SeName", node.GetSeName()); } else { menuItem.RouteName = "HomePage"; } } // Picture if (node.Id > 0 && node.ParentCategoryId == 0 && node.Published && node.PictureId != null) { menuItem.ImageId = node.PictureId; } // Apply inheritable properties. menuItem.Visible = request.Entity.Published; menuItem.PermissionNames = request.Entity.PermissionNames; if (request.Entity.NoFollow) { menuItem.LinkHtmlAttributes.Add("rel", "nofollow"); } if (request.Entity.NewWindow) { menuItem.LinkHtmlAttributes.Add("target", "_blank"); } var convertedNode = new TreeNode <MenuItem>(menuItem) { Id = categoryNode.Id }; if (categoryNode.HasChildren) { foreach (var childNode in categoryNode.Children) { convertedNode.Append(ConvertNode(request, childNode, allPictureInfos, ref randomId)); } } return(convertedNode); }