Exemplo n.º 1
0
        /// <summary>
        /// Gets products with that have an options with names
        /// </summary>
        /// <param name="optionNames">
        /// The option names.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsWithOption(
            IEnumerable <string> optionNames,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var names    = optionNames as string[] ?? optionNames.ToArray();
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsWithOption",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string>
            {
                { "optionNames", string.Join(string.Empty, names.OrderBy(x => x)) }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsKeysWithOption(names, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get products that have prices within a price range allowing for a tax modifier
        /// </summary>
        /// <param name="min">
        /// The min.
        /// </param>
        /// <param name="max">
        /// The max.
        /// </param>
        /// <param name="taxModifier">
        /// The tax modifier.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsInPriceRange(
            decimal min,
            decimal max,
            decimal taxModifier,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsInPriceRange",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string>
            {
                { "min", min.ToString(CultureInfo.InvariantCulture) },
                { "max", max.ToString(CultureInfo.InvariantCulture) },
                { "taxModifier", taxModifier.ToString(CultureInfo.InvariantCulture) }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsKeysInPriceRange(min, max, taxModifier, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets products that are in stock or do not track inventory
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <param name="includeAllowOutOfStockPurchase">
        /// The include allow out of stock purchase.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsInStock(
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection         = SortDirection.Descending,
            bool includeAllowOutOfStockPurchase = false)
        {
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsInStock",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string>
            {
                {
                    "includeAllowOutOfStockPurchase",
                    includeAllowOutOfStockPurchase.ToString()
                }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsKeysInStock(page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets products with that have an options with name and choice name
        /// </summary>
        /// <param name="optionName">
        /// The option name.
        /// </param>
        /// <param name="choiceName">
        /// The choice name.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsWithOption(
            string optionName,
            string choiceName,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsWithOption",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string>
            {
                { "optionName", optionName },
                { "choiceName", choiceName }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsKeysWithOption(optionName, choiceName, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get products for a list of manufacturers.
        /// </summary>
        /// <param name="manufacturer">
        /// The manufacturer.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsByManufacturer(
            IEnumerable <string> manufacturer,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var manufacturerArray = manufacturer as string[] ?? manufacturer.ToArray();
            var cacheKey          = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsByManufacturer",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string> {
                { "manufacturer", string.Join(string.Empty, manufacturerArray.OrderBy(x => x)) }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsKeysByManufacturer(manufacturerArray, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets products by manufacturer.
        /// </summary>
        /// <param name="manufacturer">
        /// The manufacturer.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsByManufacturer(
            string manufacturer,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsByManufacturer",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string> {
                { "manufacturer", manufacturer }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsKeysByManufacturer(manufacturer, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 7
0
        /// <summary>
        /// The get products by barcode.
        /// </summary>
        /// <param name="barcodes">
        /// The barcodes.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay GetProductsByBarcode(
            IEnumerable <string> barcodes,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var barcodesArray = barcodes as string[] ?? barcodes.ToArray();
            var cacheKey      = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>(
                "GetProductsByBarcode",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                new Dictionary <string, string>
            {
                { "barcodes", string.Join(string.Empty, barcodesArray.OrderBy(x => x)) }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (this.GetQueryResultDisplay(
                     pagedKeys ??
                     PagedKeyCache.CachePage(
                         cacheKey,
                         _productService.GetProductsByBarcode(barcodesArray, page, itemsPerPage, sortBy, sortDirection))));
        }
        /// <summary>
        /// Gets a paged collection of entity keys for a collection.
        /// </summary>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="Page{Guid}"/>.
        /// </returns>
        protected Page <Guid> GetCollectionPagedKeys(
            Guid collectionKey,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Ascending)
        {
            var args = new Dictionary <string, string>
            {
                { "collectionKey", collectionKey.ToString() }
            };

            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <CachedQueryableCollectionQueryBase <TEntity, TDisplay> >(
                "GetFromCollection",
                page,
                itemsPerPage,
                sortBy,
                sortDirection,
                args);

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            if (pagedKeys != null)
            {
                return(pagedKeys);
            }

            var provider = this.GetEntityCollectionProvider(collectionKey);

            return(PagedKeyCache.CachePage(
                       cacheKey,
                       provider.GetPagedEntityKeys(page, itemsPerPage, sortBy, sortDirection)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Searches all products
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay Search(long page, long itemsPerPage, string sortBy = "name", SortDirection sortDirection = SortDirection.Descending)
        {
            var cacheKey  = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>("Search", page, itemsPerPage, sortBy, sortDirection);
            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return(GetQueryResultDisplay(
                       pagedKeys ??
                       PagedKeyCache.CachePage(cacheKey, _productService.GetPagedKeys(page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Searches all products for a term
        /// </summary>
        /// <param name="term">
        /// The term.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public QueryResultDisplay Search(string term, long page, long itemsPerPage, string sortBy = "name", SortDirection sortDirection = SortDirection.Ascending)
        {
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>("Search", page, itemsPerPage, sortBy, sortDirection, new Dictionary <string, string> {
                { "term", term }
            });
            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return(GetQueryResultDisplay(
                       pagedKeys ??
                       PagedKeyCache.CachePage(cacheKey, _productService.GetPagedKeys(term, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Search returning an <see cref="IProductContent"/> paged collection.
        /// </summary>
        /// <param name="term">
        /// The term.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="PagedCollection"/>.
        /// </returns>
        public PagedCollection <IProductContent> TypedProductContentSearchPaged(
            string term,
            long page,
            long itemsPerPage,
            string sortBy = "name",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var cacheKey = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>("Search", page, itemsPerPage, sortBy, sortDirection, new Dictionary <string, string> {
                { "term", term }
            });
            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            return
                (_cache.GetPagedCollectionByCacheKey(
                     pagedKeys ?? _productService.GetPagedKeys(term, page, itemsPerPage, sortBy, sortDirection),
                     sortBy));
        }
        /// <summary>
        /// Gets entities from the collection.
        /// </summary>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <param name="searchTerm">
        /// The search term.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="QueryResultDisplay"/>.
        /// </returns>
        public virtual QueryResultDisplay GetFromCollection(
            Guid collectionKey,
            string searchTerm,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Ascending)
        {
            var provider = this.GetEntityCollectionProvider(collectionKey);

            if (!(provider is CachedQueryableEntityCollectionProviderBase <TEntity>))
            {
                LogHelper.Error(typeof(CachedQueryableEntityCollectionProviderBase <TEntity>), "Provider cannot be cast to Cached Queryable Provider", new InvalidOperationException("Provider cannot execute query.  Returning an empty result."));
                return(new QueryResultDisplay());
            }


            var args     = this.BuildSearchTermArgs(searchTerm);
            var cacheKey =
                PagedKeyCache.GetPagedQueryCacheKey <CachedQueryableCollectionQueryBase <TEntity, TDisplay> >(
                    "GetFromCollection",
                    page,
                    itemsPerPage,
                    sortBy,
                    sortDirection,
                    new Dictionary <string, string>
            {
                { "collectionKey", collectionKey.ToString() },
                { "searchTerm", searchTerm }
            });

            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            if (pagedKeys != null)
            {
                return(GetQueryResultDisplay(pagedKeys));
            }

            return
                (this.GetQueryResultDisplay(
                     PagedKeyCache
                     .CachePage(
                         cacheKey,
                         ((CachedQueryableEntityCollectionProviderBase <TEntity>)provider).GetPagedEntityKeys(args, page, itemsPerPage, sortBy, sortDirection))));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Search returning an <see cref="IProductContent"/> paged collection.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="PagedCollection"/>.
        /// </returns>
        public PagedCollection <IProductContent> TypedProductContentSearchPaged(
            long page,
            long itemsPerPage,
            string sortBy = "name",
            SortDirection sortDirection = SortDirection.Descending)
        {
            var cacheKey  = PagedKeyCache.GetPagedQueryCacheKey <ICachedProductQuery>("Search", page, itemsPerPage, sortBy, sortDirection);
            var pagedKeys = PagedKeyCache.GetPageByCacheKey(cacheKey);

            if (pagedKeys != null)
            {
                return(_cache.MapPagedCollection(pagedKeys, sortBy));
            }

            return
                (_cache.GetPagedCollectionByCacheKey(
                     PagedKeyCache.CachePage(cacheKey, _productService.GetPagedKeys(page, itemsPerPage, sortBy, sortDirection)),
                     sortBy));
        }