Example #1
0
        /// <summary>
        /// Gets all news
        /// </summary>
        /// <param name="languageId">Language identifier; 0 if you want to get all records</param>
        /// <param name="storeId">Store identifier; 0 if you want to get all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="title">Filter by news item title</param>
        /// <returns>News items</returns>
        public virtual IPagedList <NewsItem> GetAllNews(int languageId = 0, int storeId  = 0,
                                                        int pageIndex  = 0, int pageSize = int.MaxValue, bool showHidden = false, string title = null)
        {
            var news = _newsItemRepository.GetAllPaged(query =>
            {
                if (languageId > 0)
                {
                    query = query.Where(n => languageId == n.LanguageId);
                }

                if (!string.IsNullOrEmpty(title))
                {
                    query = query.Where(n => n.Title.Contains(title));
                }

                if (!showHidden)
                {
                    var utcNow = DateTime.UtcNow;
                    query      = query.Where(n => n.Published);
                    query      = query.Where(n => !n.StartDateUtc.HasValue || n.StartDateUtc <= utcNow);
                    query      = query.Where(n => !n.EndDateUtc.HasValue || n.EndDateUtc >= utcNow);
                }

                //Store mapping
                if (!_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <NewsItem>(storeId))
                {
                    query = query.Where(_storeMappingService.ApplyStoreMapping <NewsItem>(storeId));
                }

                return(query.OrderByDescending(n => n.StartDateUtc ?? n.CreatedOnUtc));
            }, pageIndex, pageSize);

            return(news);
        }
        /// <summary>
        /// Gets a list of products that were never sold
        /// </summary>
        /// <param name="vendorId">Vendor identifier (filter products by a specific vendor); 0 to load all records</param>
        /// <param name="storeId">Store identifier (filter products by a specific store); 0 to load all records</param>
        /// <param name="categoryId">Category identifier; 0 to load all records</param>
        /// <param name="manufacturerId">Manufacturer identifier; 0 to load all records</param>
        /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Products</returns>
        public virtual IPagedList <Product> ProductsNeverSold(int vendorId            = 0, int storeId        = 0,
                                                              int categoryId          = 0, int manufacturerId = 0,
                                                              DateTime?createdFromUtc = null, DateTime?createdToUtc = null,
                                                              int pageIndex           = 0, int pageSize = int.MaxValue, bool showHidden = false)
        {
            var simpleProductTypeId = (int)ProductType.SimpleProduct;

            var availableProductsQuery =
                from oi in _orderItemRepository.Table
                join o in _orderRepository.Table on oi.OrderId equals o.Id
                where (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) &&
                (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) &&
                !o.Deleted
                select new { ProductId = oi.ProductId };

            var query =
                from p in _productRepository.Table
                join oi in availableProductsQuery on p.Id equals oi.ProductId
                into p_oi
                from oi in p_oi.DefaultIfEmpty()
                where oi == null &&
                p.ProductTypeId == simpleProductTypeId &&
                !p.Deleted &&
                (vendorId == 0 || p.VendorId == vendorId) &&
                (showHidden || p.Published)
                select p;

            if (categoryId > 0)
            {
                query = from p in query
                        join pc in _productCategoryRepository.Table on p.Id equals pc.ProductId
                        into p_pc
                        from pc in p_pc.DefaultIfEmpty()
                        where pc.CategoryId == categoryId
                        select p;
            }

            if (manufacturerId > 0)
            {
                query = from p in query
                        join pm in _productManufacturerRepository.Table on p.Id equals pm.ProductId
                        into p_pm
                        from pm in p_pm.DefaultIfEmpty()
                        where pm.ManufacturerId == manufacturerId
                        select p;
            }

            if (!showHidden && !_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <Product>(storeId))
            {
                query = query.Where(_storeMappingService.ApplyStoreMapping <Product>(storeId));
            }

            query = query.OrderBy(p => p.Name);

            var products = new PagedList <Product>(query, pageIndex, pageSize);

            return(products);
        }
 /// <summary>
 /// Gets all message templates
 /// </summary>
 /// <param name="storeId">Store identifier; pass 0 to load all records</param>
 /// <returns>Message template list</returns>
 public virtual IList <MessageTemplate> GetAllMessageTemplates(int storeId)
 {
     return(_messageTemplateRepository.GetAll(query =>
     {
         //store mapping
         if (!_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <MessageTemplate>(storeId))
         {
             query = query.Where(_storeMappingService.ApplyStoreMapping <MessageTemplate>(storeId));
         }
         return query.OrderBy(t => t.Name);
     }, cache => cache.PrepareKeyForDefaultCache(NopMessageDefaults.MessageTemplatesAllCacheKey, storeId)));
 }
        /// <summary>
        /// Gets polls
        /// </summary>
        /// <param name="storeId">The store identifier; pass 0 to load all records</param>
        /// <param name="languageId">Language identifier; pass 0 to load all records</param>
        /// <param name="showHidden">Whether to show hidden records (not published, not started and expired)</param>
        /// <param name="loadShownOnHomepageOnly">Retrieve only shown on home page polls</param>
        /// <param name="systemKeyword">The poll system keyword; pass null to load all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>Polls</returns>
        public virtual IPagedList <Poll> GetPolls(int storeId, int languageId  = 0, bool showHidden          = false,
                                                  bool loadShownOnHomepageOnly = false, string systemKeyword = null,
                                                  int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var query = _pollRepository.Table;

            //whether to load not published, not started and expired polls
            if (!showHidden)
            {
                var utcNow = DateTime.UtcNow;
                query = query.Where(poll => poll.Published);
                query = query.Where(poll => !poll.StartDateUtc.HasValue || poll.StartDateUtc <= utcNow);
                query = query.Where(poll => !poll.EndDateUtc.HasValue || poll.EndDateUtc >= utcNow);

                //filter by store
                if (!_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <Poll>(storeId))
                {
                    query = query.Where(_storeMappingService.ApplyStoreMapping <Poll>(storeId));
                }
            }

            //load homepage polls only
            if (loadShownOnHomepageOnly)
            {
                query = query.Where(poll => poll.ShowOnHomepage);
            }

            //filter by language
            if (languageId > 0)
            {
                query = query.Where(poll => poll.LanguageId == languageId);
            }

            //filter by system keyword
            if (!string.IsNullOrEmpty(systemKeyword))
            {
                query = query.Where(poll => poll.SystemKeyword == systemKeyword);
            }

            //order records by display order
            query = query.OrderBy(poll => poll.DisplayOrder).ThenBy(poll => poll.Id);

            //return paged list of polls
            return(new PagedList <Poll>(query, pageIndex, pageSize));
        }
Example #5
0
        /// <summary>
        /// Filter hidden entries according to constraints if any
        /// </summary>
        /// <param name="query">Query to filter</param>
        /// <param name="storeId">A store identifier</param>
        /// <param name="customerRoleIds">Identifiers of customer's roles</param>
        /// <returns>Filtered query</returns>
        protected virtual IQueryable <TEntity> FilterHiddenEntries <TEntity>(IQueryable <TEntity> query, int storeId, int[] customerRoleIds)
            where TEntity : Category
        {
            //filter unpublished entries
            query = query.Where(entry => entry.Published);

            //apply store mapping constraints
            if (!_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <TEntity>(storeId))
            {
                query = query.Where(_storeMappingService.ApplyStoreMapping <TEntity>(storeId));
            }

            //apply ACL constraints
            if (!_catalogSettings.IgnoreAcl && _aclService.IsEntityAclMappingExist <TEntity>(customerRoleIds))
            {
                query = query.Where(_aclService.ApplyAcl <TEntity>(customerRoleIds));
            }

            return(query);
        }
Example #6
0
        /// <summary>
        /// Gets all blog posts
        /// </summary>
        /// <param name="storeId">The store identifier; pass 0 to load all records</param>
        /// <param name="languageId">Language identifier; 0 if you want to get all records</param>
        /// <param name="dateFrom">Filter by created date; null if you want to get all records</param>
        /// <param name="dateTo">Filter by created date; null if you want to get all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="title">Filter by blog post title</param>
        /// <returns>Blog posts</returns>
        public virtual IPagedList <BlogPost> GetAllBlogPosts(int storeId       = 0, int languageId     = 0,
                                                             DateTime?dateFrom = null, DateTime?dateTo = null,
                                                             int pageIndex     = 0, int pageSize       = int.MaxValue, bool showHidden = false, string title = null)
        {
            return(_blogPostRepository.GetAllPaged(query =>
            {
                if (dateFrom.HasValue)
                {
                    query = query.Where(b => dateFrom.Value <= (b.StartDateUtc ?? b.CreatedOnUtc));
                }
                if (dateTo.HasValue)
                {
                    query = query.Where(b => dateTo.Value >= (b.StartDateUtc ?? b.CreatedOnUtc));
                }
                if (languageId > 0)
                {
                    query = query.Where(b => languageId == b.LanguageId);
                }
                if (!string.IsNullOrEmpty(title))
                {
                    query = query.Where(b => b.Title.Contains(title));
                }
                if (!showHidden)
                {
                    query = query.Where(b => !b.StartDateUtc.HasValue || b.StartDateUtc <= DateTime.UtcNow);
                    query = query.Where(b => !b.EndDateUtc.HasValue || b.EndDateUtc >= DateTime.UtcNow);
                }

                //Store mapping
                if (!_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <BlogPost>(storeId))
                {
                    query = query.Where(_storeMappingService.ApplyStoreMapping <BlogPost>(storeId));
                }

                query = query.OrderByDescending(b => b.StartDateUtc ?? b.CreatedOnUtc);

                return query;
            }, pageIndex, pageSize));
        }
Example #7
0
        /// <summary>
        /// Gets all countries
        /// </summary>
        /// <param name="languageId">Language identifier. It's used to sort countries by localized names (if specified); pass 0 to skip it</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Countries</returns>
        public virtual IList <Country> GetAllCountries(int languageId = 0, bool showHidden = false)
        {
            var key = _staticCacheManager.PrepareKeyForDefaultCache(NopDirectoryDefaults.CountriesAllCacheKey, languageId,
                                                                    showHidden, _storeContext.CurrentStore);

            return(_staticCacheManager.Get(key, () =>
            {
                var countries = _countryRepository.GetAll(query =>
                {
                    if (!showHidden)
                    {
                        query = query.Where(c => c.Published);
                    }

                    //Store mapping
                    var storeId = _storeContext.CurrentStore.Id;

                    if (!_catalogSettings.IgnoreStoreLimitations && _storeMappingService.IsEntityMappingExists <Country>(storeId))
                    {
                        query = query.Where(_storeMappingService.ApplyStoreMapping <Country>(storeId));
                    }

                    return query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Name);
                });

                if (languageId > 0)
                {
                    //we should sort countries by localized names when they have the same display order
                    countries = countries
                                .OrderBy(c => c.DisplayOrder)
                                .ThenBy(c => _localizationService.GetLocalized(c, x => x.Name, languageId))
                                .ToList();
                }

                return countries;
            }));
        }