public DynamicContentItem[] EvaluateItems(IEvaluationContext context)
        {
            var dynamicContext = context as DynamicContentEvaluationContext;

            if (context == null)
            {
                throw new ArgumentNullException("dynamicContext");
            }
            var retVal = new List <DynamicContentItem>();

            using (var repository = _repositoryFactory())
            {
                var query = repository.PublishingGroups.Include(x => x.ContentItems)
                            .Where(x => x.IsActive)
                            .Where(x => x.StoreId == dynamicContext.StoreId)
                            .Where(x => (x.StartDate == null || dynamicContext.ToDate >= x.StartDate) && (x.EndDate == null || x.EndDate >= dynamicContext.ToDate))
                            .Where(x => x.ContentPlaces.Any(y => y.ContentPlace.Name == dynamicContext.PlaceName))
                            .OrderBy(x => x.Priority)
                            .SelectMany(x => x.ContentItems)
                            .Select(x => x.DynamicContentItemId);
                var contentItemIds = query.ToArray();
                foreach (var contentItemId in contentItemIds)
                {
                    var contentItem = _dynamicContentService.GetContentItemById(contentItemId);
                    retVal.Add(contentItem);
                }
            }

            return(retVal.ToArray());
        }
Example #2
0
        public IHttpActionResult GetDynamicContentById(string id)
        {
            var retVal = _dynamicContentService.GetContentItemById(id);

            if (retVal != null)
            {
                return(Ok(retVal.ToWebModel()));
            }
            return(NotFound());
        }
        public DynamicContentItem[] EvaluateItems(IEvaluationContext context)
        {
            var dynamicContext = context as DynamicContentEvaluationContext;

            if (context == null)
            {
                throw new ArgumentNullException("dynamicContext");
            }

            var retVal = new List <DynamicContentItem>();

            using (var repository = _repositoryFactory())
            {
                var publishings = repository.PublishingGroups.Include(x => x.ContentItems)
                                  .Where(x => x.IsActive)
                                  .Where(x => x.StoreId == dynamicContext.StoreId)
                                  .Where(x => (x.StartDate == null || dynamicContext.ToDate >= x.StartDate) && (x.EndDate == null || x.EndDate >= dynamicContext.ToDate))
                                  .Where(x => x.ContentPlaces.Any(y => y.ContentPlace.Name == dynamicContext.PlaceName))
                                  .OrderBy(x => x.Priority)
                                  .ToArray();

                //Get content items ids for publishings without ConditionExpression
                var contentItemIds = publishings.Where(x => x.ConditionExpression == null)
                                     .SelectMany(x => x.ContentItems)
                                     .Select(x => x.DynamicContentItemId)
                                     .ToList();
                foreach (var publishing in publishings.Where(x => x.ConditionExpression != null))
                {
                    try
                    {
                        //Next step need filter assignments contains dynamicexpression
                        var condition = SerializationUtil.DeserializeExpression <Func <IEvaluationContext, bool> >(publishing.ConditionExpression);
                        if (condition(context))
                        {
                            contentItemIds.AddRange(publishing.ContentItems.Select(x => x.DynamicContentItemId));
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);
                    }
                }

                foreach (var contentItemId in contentItemIds)
                {
                    var contentItem = _dynamicContentService.GetContentItemById(contentItemId);
                    retVal.Add(contentItem);
                }
            }

            return(retVal.ToArray());
        }
Example #4
0
 private void SearchContentItems(coreModel.MarketingSearchCriteria criteria, coreModel.MarketingSearchResult result)
 {
     using (var repository = _repositoryFactory())
     {
         var query = repository.Items.Where(x => x.FolderId == criteria.FolderId);
         result.TotalCount += query.Count();
         var ids = query.OrderBy(x => x.Id)
                   .Select(x => x.Id)
                   .Skip(criteria.Start)
                   .Take(criteria.Count).ToArray();
         result.ContentItems = ids.Select(x => _dynamicContentService.GetContentItemById(x)).ToList();
     }
 }
        private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback)
        {
            var result       = new BackupObject();
            var progressInfo = new ExportImportProgressInfo {
                Description = "Search promotions..."
            };

            progressCallback(progressInfo);
            var allPromotions = _marketingSearchService.SearchResources(new MarketingSearchCriteria
            {
                Count         = int.MaxValue,
                ResponseGroup = SearchResponseGroup.WithPromotions
            }).Promotions;

            progressInfo.Description = String.Format("{0} promotions loading...", allPromotions.Count());
            progressCallback(progressInfo);
            result.Promotions = allPromotions.Select(x => _promotionService.GetPromotionById(x.Id)).ToList();

            progressInfo.Description = "Search dynamic content objects...";
            progressCallback(progressInfo);

            var searchResult           = SearchInFolder(null);
            var allFolderSearchResults = searchResult != null?searchResult.Traverse(ChildrenForFolder).ToArray() : null;


            if (allFolderSearchResults != null)
            {
                progressInfo.Description = String.Format("Loading folders...");
                progressCallback(progressInfo);
                result.ContentFolders = allFolderSearchResults.SelectMany(x => x.ContentFolders).ToList();

                progressInfo.Description = String.Format("Loading places...");
                progressCallback(progressInfo);
                result.ContentPlaces = allFolderSearchResults.SelectMany(x => x.ContentPlaces)
                                       .Select(x => _dynamicContentService.GetPlaceById(x.Id))
                                       .ToList();

                progressInfo.Description = String.Format("Loading contents...");
                progressCallback(progressInfo);
                result.ContentItems = allFolderSearchResults.SelectMany(x => x.ContentItems)
                                      .Select(x => _dynamicContentService.GetContentItemById(x.Id))
                                      .ToList();

                progressInfo.Description = String.Format("Loading publications...");
                progressCallback(progressInfo);
                result.ContentPublications = allFolderSearchResults.SelectMany(x => x.ContentPublications)
                                             .Select(x => _dynamicContentService.GetPublicationById(x.Id))
                                             .ToList();
            }
            return(result);
        }