예제 #1
0
        private NavigationViewModel GetNavigationViewModel(Item categoryItem, Item datasource, Rendering currentRendering)
        {
            var cacheKey = string.Format("Navigation/{0}", categoryItem.Name);

            if (this.CurrentSiteContext.Items[cacheKey] != null)
            {
                return((NavigationViewModel)this.CurrentSiteContext.Items[cacheKey]);
            }

            var navigationViewModel = new NavigationViewModel();
            CategorySearchResults childCategories = GetChildCategories(datasource, new CommerceSearchOptions(), categoryItem);

            navigationViewModel.Initialize(currentRendering, childCategories, categoryItem.ID);
            this.CurrentSiteContext.Items[cacheKey] = navigationViewModel;

            return(navigationViewModel);
        }
        /// <summary>
        /// Builds a navigation view model or retrieves it if it already exists
        /// </summary>
        /// <param name="categoryItem">The category item to base the view model on</param>
        /// <param name="rendering">The rendering to initialize the model with</param>
        /// <returns>
        /// A category view model
        /// </returns>
        protected virtual NavigationViewModel GetNavigationViewModel(Item categoryItem, Rendering rendering)
        {
            string cacheKey = "Navigation/" + categoryItem.Name;
            bool   noCache  = (string.IsNullOrEmpty(categoryItem.Name));

            if (this.CurrentSiteContext.Items[cacheKey] != null && !noCache)
            {
                return((NavigationViewModel)this.CurrentSiteContext.Items[cacheKey]);
            }

            var navigationViewModel = new NavigationViewModel();
            CategorySearchResults childCategories = GetChildCategories(new CommerceSearchOptions(), categoryItem);

            navigationViewModel.Initialize(rendering, childCategories);
            if (noCache)
            {
                return(navigationViewModel);
            }

            this.CurrentSiteContext.Items[cacheKey] = navigationViewModel;
            return(navigationViewModel);
        }