Ejemplo n.º 1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var modelType = bindingContext.ModelType;

            if (typeof(ISearchResultModel).IsAssignableFrom(modelType))
            {
                var model = controllerContext.GetRootControllerContext().Controller.ViewData.Model as ISearchResultModel;
                return(model);
            }
            else if (typeof(IForumSearchResultModel).IsAssignableFrom(modelType))
            {
                var model = controllerContext.GetRootControllerContext().Controller.ViewData.Model as IForumSearchResultModel;
                return(model);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public override TreeNode <MenuItem> ResolveCurrentNode(ControllerContext context)
        {
            if (context == null || !ContainsProvider("catalog"))
            {
                return(base.ResolveCurrentNode(context));
            }

            TreeNode <MenuItem> currentNode = null;

            try
            {
                var rootContext = context.GetRootControllerContext();

                int currentCategoryId = GetRequestValue <int?>(rootContext, "currentCategoryId") ?? GetRequestValue <int>(rootContext, "categoryId");
                int currentProductId  = 0;

                if (currentCategoryId == 0)
                {
                    currentProductId = GetRequestValue <int?>(rootContext, "currentProductId") ?? GetRequestValue <int>(rootContext, "productId");
                }

                if (currentCategoryId == 0 && currentProductId == 0)
                {
                    // Possibly not a category node of a menu where the category tree is attached to.
                    return(base.ResolveCurrentNode(rootContext));
                }

                var cacheKey = $"sm.temp.category.breadcrumb.{currentCategoryId}-{currentProductId}";
                currentNode = Services.RequestCache.Get(cacheKey, () =>
                {
                    var root = Root;
                    TreeNode <MenuItem> node = null;

                    if (currentCategoryId > 0)
                    {
                        node = root.SelectNodeById(currentCategoryId) ?? root.SelectNode(x => x.Value.EntityId == currentCategoryId);
                    }

                    if (node == null && currentProductId > 0)
                    {
                        var productCategories = _categoryService.Value.GetProductCategoriesByProductId(currentProductId);
                        if (productCategories.Any())
                        {
                            currentCategoryId = productCategories[0].Category.Id;
                            node = root.SelectNodeById(currentCategoryId) ?? root.SelectNode(x => x.Value.EntityId == currentCategoryId);
                        }
                    }

                    return(node);
                });
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }

            return(currentNode);
        }
Ejemplo n.º 3
0
 public void Initialize(ControllerContext controllerContext)
 {
     if (!_initialized)
     {
         _controllerContext = controllerContext.GetRootControllerContext();
         IdentifyPage();
         _initialized = true;
     }
 }
Ejemplo n.º 4
0
        protected override ViewEngineResult FindView(ControllerContext context)
        {
            if (base.ViewName.IsEmpty())
            {
                throw new InvalidOperationException($"{nameof(ViewName)} is required when using {nameof(RootActionViewResult)}.");
            }

            return(base.FindView(context.GetRootControllerContext()));
        }
Ejemplo n.º 5
0
        public static bool IsBareBonePage(this ControllerContext controllerContext)
        {
            var ctx = controllerContext.GetRootControllerContext();

            if (ctx is ViewContext viewContext)
            {
                // IsPopUp or Framed
                if (viewContext.ViewBag.IsPopup == true || viewContext.ViewBag.Framed == true)
                {
                    return(true);
                }
            }

            return(false);
        }