Exemplo n.º 1
0
 public override string GetUrl(ILinkGenerator linkGenerator)
 {
     long catId;
     if (!long.TryParse(Category, out catId))
         catId = 0;
     return linkGenerator.GenerateCategoryLink(catId);
 }
        public CategoryListViewModel GetCategoryListViewModel(CategoryListPart part, ILinkGenerator linkGenerator, ICatalogApi catalogApi)
        {
            var model = new CategoryListViewModel { Title = part.Title };

            foreach (var category in part.Categories)
            {
                var itemModel = new CategoryListItemViewModel
                {
                    Url = category.TargetUrl,
                    Title = category.Title,
                    Text = category.Text
                };
                long cid;
                if (long.TryParse(category.Category, out cid))
                {
                    itemModel.Category = catalogApi.GetCategoryAsync(catalogApi.GetCategoryUri(cid)).Result;
                    if (string.IsNullOrEmpty(itemModel.Url))
                        itemModel.Url = linkGenerator.GenerateCategoryLink(cid);
                    if (string.IsNullOrEmpty(itemModel.Title))
                        itemModel.Title = itemModel.Category.DisplayName;
                    if (string.IsNullOrEmpty(itemModel.Text))
                        itemModel.Text = itemModel.Category.ShortDescription;
                }
                model.Categories.Add(itemModel);
            }

            return model;
        }
        private void AddCategory(CategoryViewModel cvm)
        {
            object cp;
            var    url          = _linkGenerator.GenerateCategoryLink(cvm.CategoryId, null, out cp);
            var    categoryPage = cp as CatalogPage;

            if (categoryPage != null && !categoryPage.IncludeInSitemap())
            {
                return;
            }

            var sme = new SiteMapEntry
            {
                Title        = cvm.DisplayName,
                Url          = url,
                LastModified = DateTime.Now
            };

            if (categoryPage != null)
            {
                sme.LastModified    = categoryPage.Published;
                sme.ChangeFrequency = categoryPage.ChangeFrequency;
                sme.Priority        = categoryPage.Priority;
                sme.Title           = categoryPage.Title;
            }
            Add(sme);
        }
        public override string GetUrl(ILinkGenerator linkGenerator)
        {
            long catId;

            if (!long.TryParse(Category, out catId))
            {
                catId = 0;
            }
            return(linkGenerator.GenerateCategoryLink(catId));
        }
        public CategoryListViewModel GetCategoryListViewModel(CategoryListPart part, ILinkGenerator linkGenerator, ICatalogApi catalogApi)
        {
            var model = new CategoryListViewModel {
                Title = part.Title
            };

            foreach (var category in part.Categories)
            {
                var itemModel = new CategoryListItemViewModel
                {
                    Url   = category.TargetUrl,
                    Title = category.Title,
                    Text  = category.Text
                };
                long cid;
                if (long.TryParse(category.Category, out cid))
                {
                    itemModel.Category = catalogApi.GetCategoryAsync(catalogApi.GetCategoryUri(cid)).Result;
                    if (string.IsNullOrEmpty(itemModel.Url))
                    {
                        itemModel.Url = linkGenerator.GenerateCategoryLink(cid);
                    }
                    if (string.IsNullOrEmpty(itemModel.Title))
                    {
                        itemModel.Title = itemModel.Category.DisplayName;
                    }
                    if (string.IsNullOrEmpty(itemModel.Text))
                    {
                        itemModel.Text = itemModel.Category.ShortDescription;
                    }
                }
                model.Categories.Add(itemModel);
            }

            return(model);
        }
Exemplo n.º 6
0
        public override PartAdapterRenderInfo PrepareRenderInfo(HtmlHelper html, ContentItem part)
        {
            var currentItem = (ListofLinksPart)part;

            html.ViewBag.ComponentID = "item_" + part.ID; // unique id for DOM element / CSS


            var viewModel = new ListofLinksViewModel
            {
                Title           = currentItem.Title,
                BackgroundColor = currentItem.BackgroundColor,
                ForegroundColor = currentItem.ForegroundColor,
                Subtitle        = currentItem.Subtitle,
                TemplateItems   = currentItem.TemplateItems,
                UseButton       = currentItem.UseButton,
                Links           = new List <ListOfLinksItem>()
            };

            foreach (var listofLinksItem in currentItem.Links)
            {
                ListOfLinksItem itemViewModel;

                string targetUrl;
                if (listofLinksItem is ProductListofLinksItem)
                {
                    var  item = (ProductListofLinksItem)listofLinksItem;
                    long pid;
                    targetUrl     = html.AbsoluteUrlWithHttp(_linkGenerator.GenerateProductLink(long.TryParse(item.Product, out pid) ? pid : (long?)null));
                    itemViewModel = new ListOfLinksItem(
                        item.Title,
                        item.Target,
                        item.LinkText,
                        targetUrl,
                        item.SuppressLinks);
                }
                else if (listofLinksItem is CategoryListofLinksItem)
                {
                    var item = (CategoryListofLinksItem)listofLinksItem;
                    targetUrl     = html.AbsoluteUrlWithHttp(_linkGenerator.GenerateCategoryLink(long.Parse(item.Category), item.ForceListPage));
                    itemViewModel = new ListOfLinksItem(
                        item.Title,
                        item.Target,
                        item.LinkText,
                        targetUrl,
                        item.SuppressLinks);
                }
                else if (listofLinksItem is ContentPageListofLinksItem)
                {
                    var item = (ContentPageListofLinksItem)listofLinksItem;
                    targetUrl = html.AbsoluteUrlWithHttp(_linkGenerator.GenerateLinkForNamedContentItem(item.ContentPage));

                    itemViewModel = new ListOfLinksItem(
                        item.Title,
                        item.Target,
                        item.LinkText,
                        targetUrl,
                        item.SuppressLinks);
                }
                else
                {
                    //targetUrl = html.AbsoluteUrlWithHttp(listofLinksItem.TargetUrl);
                    itemViewModel = new ListOfLinksItem(listofLinksItem.Title,
                                                        listofLinksItem.Target, listofLinksItem.LinkText, listofLinksItem.TargetUrl,
                                                        listofLinksItem.SuppressLinks);
                }

                // Apply suffix at this point
                if (!string.IsNullOrEmpty(listofLinksItem.UrlSuffix))
                {
                    itemViewModel.TargetUrl = string.Concat(itemViewModel.TargetUrl, listofLinksItem.UrlSuffix);
                }

                viewModel.Links.Add(itemViewModel);
            }

            return(new PartAdapterRenderInfo {
                Path = "ListOfLinks/Index", Model = viewModel
            });
        }