Ejemplo n.º 1
0
        public IViewComponentResult Invoke()
        {
            var model = new BreadCrumbsViewModel();

            if (int.TryParse(Request.Query["SectionId"], out var section_id))
            {
                model.Section = _ProductData.GetSectionById(section_id).FromDTO();
                if (model.Section.ParentId != null)
                {
                    model.Section.Parent = _ProductData.GetSectionById((int)model.Section.ParentId).FromDTO();
                }
            }

            if (int.TryParse(Request.Query["BrandId"], out var brand_id))
            {
                model.Brand = _ProductData.GetBrandById(brand_id).FromDTO();
            }

            if (int.TryParse(ViewContext.RouteData.Values["BrandId"]?.ToString(), out var product_id))
            {
                model.Product = _ProductData.GetProductById(product_id)?.Name;
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public MainWindow(MenuViewModel menuViewModel, BreadCrumbsViewModel breadCrumbsViewModel)
        {
            InitializeComponent();
            Router = mainRouter;

            menu.ViewModel        = menuViewModel;
            breadCrumbs.ViewModel = breadCrumbsViewModel;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Build the bread crumbs view model
        /// </summary>
        /// <param name="startLevel">Defines from which level the breadcrumbs will be rendered</param>
        /// <returns>Return BreadCrumbsViewModel</returns>
        public BreadCrumbsViewModel BuildBreadCrumbs(int startLevel = 0)
        {
            var currentPageModel = _requestModelAccessor.RequestModel.CurrentPageModel;
            var categoryModel    = _requestModelAccessor.RequestModel.CurrentCategoryModel;

            if (currentPageModel.Page.ParentPageSystemId == Guid.Empty && categoryModel == null)
            {
                return(new BreadCrumbsViewModel());
            }

            var curentChannelModel = _requestModelAccessor.RequestModel.ChannelModel;

            var viewModel = new BreadCrumbsViewModel {
                ContentLinks = new List <ContentLinkModel>()
            };
            var parentPages = currentPageModel.GetAncestors();

            foreach (var parentPage in parentPages.Take(parentPages.Count - startLevel).Reverse())
            {
                var pageUrl = _urlService.GetUrl(parentPage.Page);
                viewModel.ContentLinks.Add(CreateContentLink(pageUrl, parentPage.Page.Localizations.CurrentUICulture.Name));
            }

            var buildProductLinkChain = Enumerable.Empty <ContentLinkModel>();

            if (currentPageModel.Page.ParentPageSystemId == Guid.Empty)
            {
                MarketModel market = curentChannelModel.Channel.MarketSystemId.MapTo <MarketModel>();
                if (market != null && market.Market.AssortmentSystemId != Guid.Empty)
                {
                    if (categoryModel != null && market.Market.AssortmentSystemId == categoryModel.Category.AssortmentSystemId)
                    {
                        buildProductLinkChain = BuildProductLinkChain(curentChannelModel, categoryModel, _requestModelAccessor.RequestModel.CurrentProductModel);
                    }
                }
            }

            var urlToPage = _urlService.GetUrl(currentPageModel.Page);

            viewModel.ContentLinks.Add(CreateContentLink(urlToPage, currentPageModel.Page.Localizations.CurrentUICulture.Name));
            viewModel.ContentLinks.AddRange(buildProductLinkChain);
            return(viewModel);
        }