Пример #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 async Task <IPagedList <NewsItem> > GetAllNewsAsync(int languageId = 0, int storeId  = 0,
                                                                           int pageIndex  = 0, int pageSize = int.MaxValue, bool showHidden = false, string title = null)
        {
            var news = await _newsItemRepository.GetAllPagedAsync(async 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 && await _storeMappingService.IsEntityMappingExistsAsync <NewsItem>(storeId))
                {
                    query = query.Where(_storeMappingService.ApplyStoreMapping <NewsItem>(storeId));
                }

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

            return(news);
        }
Пример #2
0
        /// <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 async Task <IList <MessageTemplate> > GetAllMessageTemplatesAsync(int storeId)
        {
            return(await _messageTemplateRepository.GetAllAsync(async query =>
            {
                //store mapping
                if (!_catalogSettings.IgnoreStoreLimitations && await _storeMappingService.IsEntityMappingExistsAsync <MessageTemplate>(storeId))
                {
                    query = query.Where(_storeMappingService.ApplyStoreMapping <MessageTemplate>(storeId));
                }

                return query.OrderBy(t => t.Name);
            }, cache => cache.PrepareKeyForDefaultCache(NopMessageDefaults.MessageTemplatesAllCacheKey, storeId)));
        }
Пример #3
0
        /// <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 async Task <IPagedList <Poll> > GetPollsAsync(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 && await _storeMappingService.IsEntityMappingExistsAsync <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(await query.ToPagedListAsync(pageIndex, pageSize));
        }
Пример #4
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 async Task <IPagedList <BlogPost> > GetAllBlogPostsAsync(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(await _blogPostRepository.GetAllPagedAsync(async 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 && await _storeMappingService.IsEntityMappingExistsAsync <BlogPost>(storeId))
                {
                    query = query.Where(_storeMappingService.ApplyStoreMapping <BlogPost>(storeId));
                }

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

                return query;
            }, pageIndex, pageSize));
        }
Пример #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="customerRolesIds">Identifiers of customer's roles</param>
        /// <returns>Filtered query</returns>
        protected virtual async Task <IQueryable <TEntity> > FilterHiddenEntriesAsync <TEntity>(IQueryable <TEntity> query,
                                                                                                int storeId, int[] customerRolesIds)
            where TEntity : Manufacturer
        {
            //filter unpublished entries
            query = query.Where(entry => entry.Published);

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

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

            return(query);
        }
Пример #6
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 async Task <IList <Country> > GetAllCountriesAsync(int languageId = 0, bool showHidden = false)
        {
            var key = _staticCacheManager.PrepareKeyForDefaultCache(NopDirectoryDefaults.CountriesAllCacheKey, languageId,
                                                                    showHidden, await _storeContext.GetCurrentStoreAsync());

            return(await _staticCacheManager.GetAsync(key, async() =>
            {
                var countries = await _countryRepository.GetAllAsync(async query =>
                {
                    if (!showHidden)
                    {
                        query = query.Where(c => c.Published);
                    }

                    //Store mapping
                    var storeId = (await _storeContext.GetCurrentStoreAsync()).Id;
                    if (!_catalogSettings.IgnoreStoreLimitations && await _storeMappingService.IsEntityMappingExistsAsync <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 = await countries
                                .ToAsyncEnumerable()
                                .OrderBy(c => c.DisplayOrder)
                                .ThenByAwait(async c => await _localizationService.GetLocalizedAsync(c, x => x.Name, languageId))
                                .ToListAsync();
                }

                return countries;
            }));
        }