public static string GetPaginationUrl(this UrlHelper url, Category c, int? offset, int? count)
        {
            // reads the search, sorting, and filter parameters from the route data.
            // all other overrides do not (ie. jumping from category to category resets
            // those fields, but paging in a result set obviously should not).

            var q = url.RequestContext.HttpContext.Request.QueryString["q"];
            var s = url.RequestContext.HttpContext.Request.QueryString["sort"];
            var afford = url.RequestContext.HttpContext.Request.QueryString["afford"];
            var tag = url.RequestContext.HttpContext.Request.QueryString["tag"];

            return GetCategoryUrl(url, c, tag, q, s, String.IsNullOrEmpty(afford) ? (bool?)null : true, offset, count);
        }
        public static string GetCategoryUrl(this UrlHelper url, Category c, string tag, string q, string s, bool? afford, int? offset, int? count)
        {
            var d = new RouteValueDictionary
            {
                { "tag", tag },
                { "q", q },
                { "s", s },
                { "afford", afford },
                { "offset", offset },
                { "count", count },
            };

            var name = "CatalogKeys" + c.Key.Length;
            while (null != c && c.Key.Length > 1)
            {
                d["key" + (c.Key.Length-2)] = c.Slug;
                c = c.Parent;
            }

            return url.RouteUrl(name, d);
        }
 public static string GetCategoryUrl(this UrlHelper url, Category c, int? offset, int? count)
 {
     return GetCategoryUrl(url, c, null, null, null, null, offset, count);
 }
 public static string GetCategoryUrl(this UrlHelper url, Category c)
 {
     return GetCategoryUrl(url, c, null, null);
 }
 public static string GetTagUrl(this UrlHelper url, Category c, string tag)
 {
     return GetCategoryUrl(url, c, tag, null, null, null, null, null);
 }
		public static MvcHtmlString CategoryNode(this HtmlHelper html, UrlHelper url, Category c, Func<Category, bool> expanded = null)
		{
			var buf = new StringBuilder();
		    var exp = (null != expanded && expanded(c));
            buf.Append(exp ? "<li class=\"expanded\">" : "<li>");
            buf.AppendFormat("<span class=\"ui-icon {0}\" style=\"float: left;\"></span>",
                null != c.Children && c.Children.Count > 0
                    ? (exp ? "ui-icon-circlesmall-minus expandable" : "ui-icon-circlesmall-plus expandable")
                    : "ui-icon-placeholder");
			buf.Append(html.CategoryLink(url, c));
			if (null != c.Children && c.Children.Count > 0)
			{
                buf.Append("<ul>");
				foreach (var child in c.Children.Values)
				{
					buf.Append(html.CategoryNode(url, child, expanded));
				}
				buf.Append("</ul>");
			}
			buf.Append("</li>");
			return MvcHtmlString.Create(buf.ToString());
		}
		public static MvcHtmlString CategoryLink(this HtmlHelper html, UrlHelper url, Category c)
		{
			return MvcHtmlString.Create("<a href=\"" + url.GetCategoryUrl(c) + "\">" + (c.Name == "Catalog" ? "All Products" : c.Name) + "</a>");
		}
Exemplo n.º 8
0
 public IList<CatalogProduct> SearchProducts(string catalog, Category category, string query)
 {
     query = query.ToLowerInvariant();
     return category.Products.Where(x => x.Name.ToLowerInvariant().Contains(query)).ToList();
 }
Exemplo n.º 9
0
 public IList<CatalogProduct> GetProducts(string catalog, Category category)
 {
     return category.Products;
 }
Exemplo n.º 10
0
        public CatalogData(
            IApplicationConfiguration configuration,
            Catalog catalog,
            Product[] products)
        {

            // set the root category
            Categories = new Category
            {
                Key = new string[] {"catalog"},
                Slug = "catalog",
                Name = "Catalog",
                Products = new List<CatalogProduct>(products.Length),
            };

            // convert products
            Products = new Dictionary<string, CatalogProduct>(products.Length);
            foreach (var p in products)
            {
                // find/build the category
                var category = Categories;
                for (int i = 1; i < p.Category.Length; i++)
                {
                    var slug = p.Category[i].ToSlug();
                    if (null == category.Children)
                    {
                        category.Children = new Dictionary<string, Category>();
                    }
                    if (!category.Children.ContainsKey(slug))
                    {
                        category.Children[slug] = new Category
                                                        {
                                                            Key = category.Key.Concat(new[] {slug}).ToArray(),
                                                            Name = p.Category[i],
                                                            Parent = category,
                                                            Slug = slug,
                                                            Products = new List<CatalogProduct>(100),
                                                        };
                    }
                    category = category.Children[slug];
                }

                // tranform the product
                var x = new CatalogProduct
                {
                    Catalog = catalog,
                    Id = p.ProductId,
                    Name = p.Name,
                    Sku = p.Sku,
                    Manufacturer = p.Manufacturer,
                    Brand = p.Brand,
                    Model = p.Model,
                    Description = p.Description,
                    Features = p.Features,
                    Warranty = p.Warranty,
                    CountryOfOrigin = p.CountryOfOrigin,
                    Category = category,
                    Tags = p.Tags,
                    Price = (int)Math.Ceiling(catalog.GetPrice(p) * configuration.PointsPerDollar),
                    Options = null == p.Options
                        ? new List<CatalogProductOption>()
                        : p.Options.Select(i => {
                            var source = i.GetBestSource();
                            var price = null == source ? null : source.Pricing;
                            return new CatalogProductOption
                            {
                                Sku = i.Sku,
                                Name = i.Name,
                                Price = price == null ? null : (int?)Math.Ceiling(configuration.PointsPerDollar * catalog.GetPrice(p, i.Name)),
                            };
                        }).ToList(),
                };
                Products[x.Id] = x;

                // add to various categories
                do
                {
                    category.Products.Add(x);
                    category = category.Parent;
                } while (category != null);
            }

        }