示例#1
0
 public static int CurrentTopicId(this IDisplayHelper displayHelper)
 => displayHelper.CurrentPageType() == "topic" ? displayHelper.CurrentPageId().Convert <int>() : 0;
示例#2
0
 public static int CurrentProductId(this IDisplayHelper displayHelper)
 => displayHelper.CurrentPageType() == "product" ? displayHelper.CurrentPageId().Convert <int>() : 0;
示例#3
0
 public static int CurrentCategoryId(this IDisplayHelper displayHelper)
 => displayHelper.CurrentPageType() == "category" ? displayHelper.CurrentPageId().Convert <int>() : 0;
示例#4
0
 public static int CurrentManufacturerId(this IDisplayHelper displayHelper)
 => displayHelper.CurrentPageType() == "manufacturer" ? displayHelper.CurrentPageId().Convert <int>() : 0;
示例#5
0
            /// <summary>
            /// Find the selected node in any registered menu
            /// </summary>
            public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
            {
                var executedContext = await next();

                if (context.HttpContext.Request.IsAjaxRequest())
                {
                    return;
                }

                //if (filterContext.HttpContext.Request.HttpMethod != "GET")
                //	return;

                if (!executedContext.Result.IsHtmlViewResult())
                {
                    return;
                }

                if (executedContext.RouteData.Values.GetAreaName().EqualsNoCase("admin"))
                {
                    return;
                }

                var selectedNode = await ResolveCurrentNodeAsync(executedContext);

                object nodeData;

                if (selectedNode == null)
                {
                    nodeData = new
                    {
                        type = _displayHelper.CurrentPageType(),
                        id   = _displayHelper.CurrentPageId()
                    };
                }
                else
                {
                    var httpContext = context.HttpContext;

                    // So that other actions/partials can access this.
                    httpContext.Items["SelectedNode"] = selectedNode;

                    // Add custom meta head part (mainly for client scripts)
                    var    nodeType = (selectedNode.Value.EntityName ?? _displayHelper.CurrentPageType()).ToLowerInvariant();
                    object nodeId   = selectedNode.Id;
                    if (_displayHelper.IsHomePage())
                    {
                        nodeId = 0;
                    }
                    else if (nodeType == "system")
                    {
                        nodeId = _displayHelper.CurrentPageId();
                    }

                    nodeData = new
                    {
                        type       = nodeType,
                        id         = nodeId,
                        menuItemId = selectedNode.Value.MenuItemId,
                        entityId   = selectedNode.Value.EntityId,
                        parentId   = selectedNode.Parent?.IsRoot == true ? 0 : selectedNode.Parent?.Id
                    };
                }

                // Add node data to head meta property as JSON.
                _assetBuilder.AddHtmlContent("head", new HtmlString("<meta property='sm:pagedata' content='{0}' />".FormatInvariant(JsonConvert.SerializeObject(nodeData))));
            }