public IHttpActionResult DynamicContentPublicationsSearch(DynamicContentPublicationSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <webModel.DynamicContentPublication>();
            var publicationSearchResult = _dynamicConentSearchService.SearchContentPublications(criteria);

            retVal.TotalCount = publicationSearchResult.TotalCount;
            retVal.Results    = publicationSearchResult.Results.Select(x => x.ToWebModel()).ToList();
            return(Ok(retVal));
        }
        protected virtual IList <SortInfo> BuildSortExpression(DynamicContentPublicationSearchCriteria criteria)
        {
            var sortInfos = criteria.SortInfos;

            if (sortInfos.IsNullOrEmpty())
            {
                sortInfos = new[]
                {
                    new SortInfo
                    {
                        SortColumn    = nameof(DynamicContentPublication.Priority),
                        SortDirection = SortDirection.Ascending
                    }
                };
            }

            return(sortInfos);
        }
Пример #3
0
        public async Task <DynamicContentPublicationSearchResult> SearchContentPublicationsAsync(DynamicContentPublicationSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchContentPublicationsAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(DynamicContentPublicationCacheRegion.CreateChangeToken());
                var retVal = AbstractTypeFactory <DynamicContentPublicationSearchResult> .TryCreateInstance();
                using (var repository = _repositoryFactory())
                {
                    var query = repository.PublishingGroups;
                    if (!string.IsNullOrEmpty(criteria.Store))
                    {
                        query = query.Where(x => x.StoreId == criteria.Store);
                    }
                    if (criteria.OnlyActive)
                    {
                        query = query.Where(x => x.IsActive == true);
                    }
                    if (!string.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(q => q.Name.Contains(criteria.Keyword));
                    }
                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[] { new SortInfo {
                                                SortColumn = ReflectionUtility.GetPropertyName <DynamicContentPublication>(x => x.Name), SortDirection = SortDirection.Ascending
                                            } };
                    }
                    query = query.OrderBySortInfos(sortInfos);

                    retVal.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var ids = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                        retVal.Results = await _dynamicContentService.GetPublicationsByIdsAsync(ids);
                    }
                }
                return retVal;
            }));
        }
Пример #4
0
        public GenericSearchResult <coreModel.DynamicContentPublication> SearchContentPublications(DynamicContentPublicationSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <coreModel.DynamicContentPublication>();

            using (var repository = _repositoryFactory())
            {
                var query = repository.PublishingGroups;
                if (!string.IsNullOrEmpty(criteria.Store))
                {
                    query = query.Where(x => x.StoreId == criteria.Store);
                }
                if (criteria.OnlyActive)
                {
                    query = query.Where(x => x.IsActive == true);
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(q => q.Name.Contains(criteria.Keyword));
                }
                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.DynamicContentPublication>(x => x.Name), SortDirection = SortDirection.Ascending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();

                var ids = query.Select(x => x.Id)
                          .Skip(criteria.Skip)
                          .Take(criteria.Take).ToArray();
                retVal.Results = _dynamicContentService.GetPublicationsByIds(ids);
            }
            return(retVal);
        }
        protected virtual IQueryable <DynamicContentPublishingGroupEntity> BuildQuery(DynamicContentPublicationSearchCriteria criteria, IMarketingRepository repository)
        {
            var query = repository.PublishingGroups;

            if (!string.IsNullOrEmpty(criteria.Store))
            {
                query = query.Where(x => x.StoreId == criteria.Store);
            }

            if (criteria.OnlyActive)
            {
                query = query.Where(x => x.IsActive == true);
            }

            if (criteria.StartDate != null)
            {
                query = query.Where(x => x.StartDate == null || criteria.StartDate >= x.StartDate);
            }

            if (criteria.EndDate != null)
            {
                query = query.Where(x => x.EndDate == null || x.EndDate >= criteria.EndDate);
            }

            if (!string.IsNullOrEmpty(criteria.PlaceName))
            {
                query = query.Where(x => x.ContentPlaces.Any(y => y.ContentPlace.Name == criteria.PlaceName));
            }

            if (!string.IsNullOrEmpty(criteria.Keyword))
            {
                query = query.Where(q => q.Name.Contains(criteria.Keyword));
            }
            return(query);
        }
        public async Task <DynamicContentPublicationSearchResult> SearchContentPublicationsAsync(DynamicContentPublicationSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchContentPublicationsAsync), criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(DynamicContentPublicationCacheRegion.CreateChangeToken());
                var retVal = AbstractTypeFactory <DynamicContentPublicationSearchResult> .TryCreateInstance();
                using (var repository = _repositoryFactory())
                {
                    var sortInfos = BuildSortExpression(criteria);
                    var query = BuildQuery(criteria, repository);

                    retVal.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                                  .Select(x => x.Id)
                                  .Skip(criteria.Skip).Take(criteria.Take)
                                  .ToArrayAsync();

                        retVal.Results = (await _dynamicContentService.GetPublicationsByIdsAsync(ids))
                                         .OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                    }
                }
                return retVal;
            }));
        }
 protected virtual GenericSearchResult <DynamicContentPublication> LoadContentPublications(DynamicContentPublicationSearchCriteria criteria)
 {
     return(_dynamicContentSearchService.SearchContentPublications(criteria));
 }