public ActionResult List(int page = 1, string search = "") { Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetExpires(DateTime.Now.AddSeconds(600)); Response.Cache.SetValidUntilExpires(true); if (search != "") { this.Session["search"] = search; } _productCollection = _productCollectionFactory.Create((string)this.Session["search"], page, 13); _model = new ProductListViewModel() { Products = _productCollection.ProductInfo.Products, PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalPages = _productCollection.ProductInfo.Pages } }; return(View(_model)); }
/// <summary> /// Gets the collection of all products in the collection. /// </summary> /// <param name="value"> /// The <see cref="ProductCollection"/>. /// </param> /// <param name="merchelloHelper"> /// The <see cref="MerchelloHelper"/>. /// </param> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// Number of items per page. /// </param> /// <param name="sortBy"> /// The sort field. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="IEnumerable{IProductContent}"/>. /// </returns> internal static PagedCollection <IProductContent> GetProducts( this IProductCollection value, MerchelloHelper merchelloHelper, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Ascending) { ProductSortField order; switch (sortBy.ToLowerInvariant()) { case "price": order = ProductSortField.Price; break; case "sku": order = ProductSortField.Sku; break; case "name": default: order = ProductSortField.Name; break; } return (merchelloHelper.ProductContentQuery() .Page(page) .ConstrainBy(value) .ItemsPerPage(itemsPerPage) .OrderBy(order, sortDirection) .Execute()); }
/// <summary> /// Gets the collection of all products in the collection. /// </summary> /// <param name="value"> /// The <see cref="ProductCollection"/>. /// </param> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// Number of items per page. /// </param> /// <param name="sortBy"> /// The sort field. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <param name="enableDataModifiers"> /// A value indicating whether or not to enable data modifiers in the MerchelloHelper /// </param> /// <returns> /// The <see cref="IEnumerable{IProductContent}"/>. /// </returns> public static IEnumerable <IProductContent> GetProducts( this IProductCollection value, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Ascending, bool enableDataModifiers = true) { return(value.GetProductsPaged(page, itemsPerPage, sortBy, sortDirection, enableDataModifiers).Items); }
/// <inheritdoc/> public TreeNode<IProductCollection> GetTreeByValue(IProductCollection value) { var cacheKey = GetCacheKey("GetTreeByValue"); var tree = (TreeNode<IProductCollection>)Cache.GetCacheItem(cacheKey); if (tree != null) return tree; var root = GetTreeContaining(value); tree = root.FirstByValue(value); return tree != null ? (TreeNode<IProductCollection>)Cache.GetCacheItem(cacheKey, () => tree) : null; }
/// <summary> /// Gets the paged collection of products in the collection. /// </summary> /// <param name="value"> /// The <see cref="ProductCollection"/>. /// </param> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// Number of items per page. /// </param> /// <param name="sortBy"> /// The sort field. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <param name="enableDataModifiers"> /// A value indicating whether or not to enable data modifiers in the MerchelloHelper /// </param> /// <returns> /// The <see cref="IEnumerable{IProductContent}"/>. /// </returns> public static PagedCollection <IProductContent> GetProductsPaged( this IProductCollection value, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Ascending, bool enableDataModifiers = true) { var merchelloHelper = new MerchelloHelper(enableDataModifiers); return(value.GetProducts(merchelloHelper, page, itemsPerPage, sortBy, sortDirection)); }
/// <summary> /// Gets the <see cref="TreeNode{IProductCollection}"/>. /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="TreeNode{IProductCollection}"/>. /// </returns> /// <exception cref="NullReferenceException"> /// Throws a null reference exception if the collection could not be found in the cached collection tree. /// </exception> private static TreeNode <IProductCollection> AsTreeNode(this IProductCollection value) { var tree = TreeQuery().GetTreeByValue(value); if (tree != null) { return(tree); } var nullRef = new NullReferenceException("The product collection was not found in Tree cache"); MultiLogHelper.Error(typeof(ProductCollectionExtensions), "Tree nod found for collection", nullRef); throw nullRef; }
/// <inheritdoc/> public TreeNode <IProductCollection> GetTreeByValue(IProductCollection value) { var cacheKey = GetCacheKey("GetTreeByValue"); var tree = (TreeNode <IProductCollection>)Cache.GetCacheItem(cacheKey); if (tree != null) { return(tree); } var root = GetTreeContaining(value); tree = root.FirstByValue(value); return(tree != null ? (TreeNode <IProductCollection>)Cache.GetCacheItem(cacheKey, () => tree) : null); }
public void XmlDataSource_SerializeCollectionCompareTest() { string outputFile = @".\products.xml"; IProductCollection products = new ProductCollection(); products.AddNew("Apple"); products.AddNew("Banana"); products.AddNew("Apple"); products.AddNew("Apple"); XmlSource.Save(products, outputFile); IProductCollection products2 = XmlSource.Load(typeof(ProductCollection), outputFile) as IProductCollection; Assert.IsNotNull(products2, "ProductCollection could not be rehydrated"); Assert.AreEqual(products.Count, products2.Count, "ProductCollection was not rehydrated with an incorrect count"); //Cleanup System.IO.File.Delete(outputFile); }
/// <summary> /// Get the parent <see cref="ProductCollection"/>. /// </summary> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="ProductCollection"/>. /// </returns> public static IProductCollection Parent(this IProductCollection value) { return(value.ParentKey == null ? null : GetByKey(value.ParentKey.Value)); }
/// <summary> /// Adds a constraint by a <see cref="IProductCollection"/>. /// </summary> /// <param name="builder"> /// The builder. /// </param> /// <param name="collection"> /// The collection. /// </param> /// <returns> /// The <see cref="IProductContentQueryBuilder"/>. /// </returns> public static IProductContentQueryBuilder ConstrainBy(this IProductContentQueryBuilder builder, IProductCollection collection) { builder.AddConstraint(collection); return(builder); }
/// <inheritdoc /> public TreeNode<IProductCollection> GetTreeWithRoot(IProductCollection collection) { return new TreeNode<IProductCollection>(collection).Populate(GetAll()); }
/// <inheritdoc /> public TreeNode<IProductCollection> GetTreeContaining(IProductCollection collection) { var trees = GetRootTrees(); return trees.FirstOrDefault(tree => tree.Flatten().Any(node => node.Key == collection.Key)); }
/// <summary> /// Gets the descendants of the <see cref="IProductCollection"/> including itself. /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="predicate"> /// The predicate. /// </param> /// <returns> /// The <see cref="IEnumerable{IProductCollection}"/>. /// </returns> public static IEnumerable <IProductCollection> DescendantsOrSelf(this IProductCollection value, Expression <Func <IProductCollection, bool> > predicate = null) { return(value.AsTreeNode().DescendantsOrSelf().Values(predicate)); }
/// <summary> /// Gets the collection of all products in the collection. /// </summary> /// <param name="value"> /// The <see cref="ProductCollection"/>. /// </param> /// <param name="enableDataModifiers"> /// A value indicating whether or not to enable data modifiers in the MerchelloHelper /// </param> /// <returns> /// The <see cref="IEnumerable{IProductContent}"/>. /// </returns> public static IEnumerable <IProductContent> GetProducts(this IProductCollection value, bool enableDataModifiers = true) { return(value.GetProducts(1, long.MaxValue, enableDataModifiers: enableDataModifiers)); }
/// <summary> /// Adds a constraint by a <see cref="IProductCollection"/>. /// </summary> /// <param name="builder"> /// The builder. /// </param> /// <param name="collection"> /// The collection. /// </param> /// <returns> /// The <see cref="IProductContentQueryBuilder"/>. /// </returns> public static IProductContentQueryBuilder ConstrainBy(this IProductContentQueryBuilder builder, IProductCollection collection) { builder.AddConstraint(collection); return builder; }
/// <summary> /// Gets the first descendant matching the expression /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="predicate"> /// The predicate. /// </param> /// <returns> /// The <see cref="IProductCollection"/>. /// </returns> public static IProductCollection Descendant(this IProductCollection value, Expression <Func <IProductCollection, bool> > predicate) { return(value.AsTreeNode().Descendants().Values(predicate).FirstOrDefault()); }
public ProductStorageManager(IProductCollection productCollection) { _productCollection = productCollection; }
public ProductRepository(IProductCollection productCollection) { _productCollection = productCollection; }
public static IEnumerable <Product> GetProductByName(this IProductCollection collection, string name) { return(collection.GetAll().Where(a => a.Name == name)); }
public void TestInitialize() { products = new ProductCollection(); }
/// <inheritdoc /> public TreeNode <IProductCollection> GetTreeWithRoot(IProductCollection collection) { return(new TreeNode <IProductCollection>(collection).Populate(GetAll())); }
/// <inheritdoc /> public TreeNode <IProductCollection> GetTreeContaining(IProductCollection collection) { var trees = GetRootTrees(); return(trees.FirstOrDefault(tree => tree.Flatten().Any(node => node.Key == collection.Key))); }
public CartStorageManager(ICartCollection cartCollection, IProductCollection productCollection) { _cartCollection = cartCollection; _productCollection = productCollection; }
/// <summary> /// Gets the siblings of the <see cref="IProductCollection"/>. /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="predicate"> /// An optional lambda expression /// </param> /// <returns> /// The <see cref="IEnumerable{IProductCollection}"/>. /// </returns> public static IEnumerable <IProductCollection> Ancestors(this IProductCollection value, Expression <Func <IProductCollection, bool> > predicate = null) { return(value.AsTreeNode().Ancestors().Values(predicate)); }
public ProductController(IProductCollection productCollection, ICategoryCollection categoryCollection, IStorage storage) : base(categoryCollection) { this._productCollection = productCollection; this._categoryCollection = categoryCollection; this._storage = storage; }