private void InitBreadcrumbs() { BreadCrumbsHelper.RegisterPattern(new BreadCrumbPattern("^/" + RouteConfig.BlogUrl + "/tag/[^/]+$", url => { var res = new List <BreadCrumb>(); var pageService = DependencyResolver.Current.GetService <IPageService>(); var blogTitle = pageService.GetPage(RouteConfig.BlogUrl).Title; res.Add(new BreadCrumb() { IsLast = false, Title = blogTitle, Url = "/" + RouteConfig.BlogUrl }); var tag = Regex.Match(url, "^/" + RouteConfig.BlogUrl + "/tag/([^/]+)$").Groups[1].Value; res.Add(new BreadCrumb() { IsLast = true, Title = "Записи с тегом «" + tag + "»", Url = url }); return(res); })); BreadCrumbsHelper.RegisterPattern(new BreadCrumbPattern("^/" + RouteConfig.BlogUrl + "/[^/]+$", url => { var res = new List <BreadCrumb>(); var pageService = DependencyResolver.Current.GetService <IPageService>(); var blogTitle = pageService.GetPage(RouteConfig.BlogUrl).Title; res.Add(new BreadCrumb() { IsLast = false, Title = blogTitle, Url = "/" + RouteConfig.BlogUrl }); var relativeUrl = Regex.Match(url, "^/" + RouteConfig.BlogUrl + "/(.+)$").Groups[1].Value; var newsService = DependencyResolver.Current.GetService <INewsItemService>(); var title = newsService.GetNewsItem(relativeUrl, false).Title; res.Add(new BreadCrumb() { IsLast = true, Title = title, Url = url }); return(res); })); }
private void InitBreadcrumbs() { string SHOP_URL = RouteConfig.ShopUrl; var shopService = DependencyResolver.Current.GetService <IShopService>(); var categoryService = DependencyResolver.Current.GetService <IShopCategoryService>(); var heartService = DependencyResolver.Current.GetService <IHeartService>(); // для товаров и категорий BreadCrumbsHelper.RegisterPattern(new BreadCrumbPattern( "^/" + SHOP_URL + @"(/[a-zA-Z_0-9а-яА-Я-]+)+", url => { var shopUrl = url.Replace("/" + SHOP_URL, ""); var res = new List <BreadCrumb>(); var pageService = DependencyResolver.Current.GetService <IPageService>(); var shopTitle = pageService.GetPage(SHOP_URL).Title; res.Add(new BreadCrumb() { IsLast = false, Title = shopTitle, Url = "/" + SHOP_URL }); var elements = shopUrl.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); for (int index = 0; index < elements.Length; index++) { var element = elements[index]; if (index != elements.Length - 1) // не последний элемент - всегда категория { if (categoryService.CategoryExists(element)) { var cat = categoryService.GetCategory(element); res.Add(new BreadCrumb() { IsLast = false, Title = cat.Name, Url = $"/{SHOP_URL}/" + string.Join("/", elements.Take(index + 1)) }); } } else // последний элемент - Товар или категория { var heart = heartService.GetHeart(element); if (heart.Type == typeof(GoodsItem).FullName) { var goodsItem = shopService.GetGoods(element, false); res.Add(new BreadCrumb() { IsLast = true, Title = goodsItem.Name, Url = url }); } else if (heart.Type == typeof(Category).FullName) { var cat = categoryService.GetCategory(element); res.Add(new BreadCrumb() { IsLast = true, Title = cat.Name, Url = url }); } } } return(res); } )); }