public ProductListViewModel GetProductListViewModel(ProductListPart part, ILinkGenerator linkGenerator, ICatalogApi catalogApi) { var model = new ProductListViewModel {Title = part.Title}; foreach (var product in part.Products) { var itemModel = new ProductListItemViewModel { Url = product.TargetUrl, Title = product.Title, Text = product.Text }; long pid; if (long.TryParse(product.Product, out pid)) { itemModel.Product = catalogApi.GetProductAsync(catalogApi.GetProductUri(pid)).Result; if (string.IsNullOrEmpty(itemModel.Url)) itemModel.Url = linkGenerator.GenerateProductLink(pid); if (string.IsNullOrEmpty(itemModel.Title)) itemModel.Title = itemModel.Product.DisplayName; if (string.IsNullOrEmpty(itemModel.Text)) itemModel.Text = itemModel.Product.ShortDescription; } model.Products.Add(itemModel); } return model; }
protected Product GetProduct(HtmlHelper html, IProductPart item) { if (item == null) { return(null); } Product product = null; var currentController = html.ViewContext.Controller as INimbusContentController; try { long pid; if (!long.TryParse(item.Product, out pid)) { return(null); } if (currentController == null || (!currentController.Products.TryGetValue(pid, out product) && !currentController.BogusProductIds.Contains(pid))) { product = _catalogApi.GetProductAsync(_catalogApi.GetProductUri(pid)).Result; } } catch (Exception e) { Logger.Error(e, "Unable to retrieve product with product ID {0}", item.Product); product = null; } return(product); }
private void AddContentPages(string url) { var root = GetRootItem(url); // if (root is LanguageRoot) root = root.Parent; // TODO rewrite url to be below LanguageRoot foreach (var item in GetDescendants(root)) { if (!item.IsPublished()) { continue; } var page = item as PageModelBase; if (page != null && !page.IncludeInSitemap()) { continue; } // special case of generic ProductPage and CatalogPage // have to configure generic page in N2 to include in sitemap in order to get all the products and categories to be included in sitemap // but don't want the generic page naked without reference to an ID to be in the sitemap var productPage = item as ProductPage; if ((productPage != null && string.IsNullOrEmpty(productPage.ProductID)) || (item is CatalogPage && string.IsNullOrEmpty(((CatalogPage)item).CategoryID))) { continue; } if (productPage != null) { long pid; if (long.TryParse(productPage.ProductID, out pid)) { var prod = _catalogApi.GetProductAsync(_catalogApi.GetProductUri(pid)).Result; if (prod != null && prod.CustomAttributes.ValueByName("NoIndex", false)) { continue; } } } var se = new SiteMapEntry { Title = item.Title, Url = item.Url, LastModified = item.Published, }; if (page != null) { se.ChangeFrequency = page.ChangeFrequency; se.Priority = page.Priority; } Add(se); } }
public string GetPageTitleFromModel(ProductDetailPageViewModel model) { if (model != null) { var title = model.Product.CustomAttributes.ValueByName(SuperDuperTitleTagAttributeName); if (!string.IsNullOrEmpty(title)) { return(title); } if (model.ParentProductId != 0 && model.ParentProductId != model.Product.Id) { var parentProd = _catApi.GetProductAsync(_catApi.GetProductUri(model.ParentProductId)).Result; title = parentProd.CustomAttributes.ValueByName(SuperDuperTitleTagAttributeName); if (!string.IsNullOrEmpty(title)) { return(title); } } var res = Res.PageTitle_Product; if (!string.IsNullOrEmpty(res)) { var idx = res.IndexOf(ProductNameSubstititionToken, StringComparison.InvariantCultureIgnoreCase); if (idx >= 0) { string name; if (!string.IsNullOrEmpty(model.Product.DisplayName)) { name = model.Product.DisplayName; } else { name = model.Product.Id.ToString(CultureInfo.InvariantCulture); } return(res.Remove(idx, ProductNameSubstititionToken.Length).Insert(idx, name)); } return(res); } } return(string.Empty); }
private string ConvertSelectedItemsToJson(string selectedItems) { var sia = string.IsNullOrEmpty(selectedItems) ? new string[0] : selectedItems.Split(','); var currentContext = System.Web.HttpContext.Current; var products = sia.AsParallel().Select(pid => { long prodId; if (!long.TryParse(pid, out prodId)) { return(null); } System.Web.HttpContext.Current = currentContext; var p = _catalogApi.GetProductAsync(_catalogApi.GetProductUri(prodId)).Result; if (p == null) { return(null); } return(new ProductEntityViewModel { Id = p.Id, Title = p.DisplayName, Description = p.ShortDescription }); }).Where(product => product != null).ToList(); var serializer = new DataContractJsonSerializer(typeof(ProductEntityViewModel[])); var ms = new MemoryStream(); serializer.WriteObject(ms, products.ToArray()); var json = ms.ToArray(); ms.Close(); return(Encoding.UTF8.GetString(json, 0, json.Length)); }
public ProductListViewModel GetProductListViewModel(ProductListPart part, ILinkGenerator linkGenerator, ICatalogApi catalogApi) { var model = new ProductListViewModel { Title = part.Title }; foreach (var product in part.Products) { var itemModel = new ProductListItemViewModel { Url = product.TargetUrl, Title = product.Title, Text = product.Text }; long pid; if (long.TryParse(product.Product, out pid)) { itemModel.Product = catalogApi.GetProductAsync(catalogApi.GetProductUri(pid)).Result; if (string.IsNullOrEmpty(itemModel.Url)) { itemModel.Url = linkGenerator.GenerateProductLink(pid); } if (string.IsNullOrEmpty(itemModel.Title)) { itemModel.Title = itemModel.Product.DisplayName; } if (string.IsNullOrEmpty(itemModel.Text)) { itemModel.Text = itemModel.Product.ShortDescription; } } model.Products.Add(itemModel); } return(model); }