public GenericSearchResult <coreModel.DynamicContentItem> SearchContentItems(DynamicContentItemSearchCriteria criteria) { var retVal = new GenericSearchResult <coreModel.DynamicContentItem>(); using (var repository = _repositoryFactory()) { var query = repository.Items; if (!string.IsNullOrEmpty(criteria.FolderId)) { query = query.Where(x => x.FolderId == criteria.FolderId); } 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.DynamicContentItem>(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.GetContentItemsByIds(ids); } return(retVal); }
public DynamicContentItem[] GetContentItemsByIds(string[] ids) { var cacheKey = GetCacheKey("IDynamicContentService.GetContentItemsByIds", string.Join(", ", ids)); var retVal = _cacheManager.Get(cacheKey, RegionName, () => _contentService.GetContentItemsByIds(ids)); return(retVal); }
public IHttpActionResult GetDynamicContentById(string id) { var retVal = _dynamicContentService.GetContentItemsByIds(new[] { id }).FirstOrDefault(); if (retVal != null) { return(Ok(retVal.ToWebModel())); } return(NotFound()); }
public DynamicContentItem[] EvaluateItems(IEvaluationContext context) { var dynamicContext = context as DynamicContentEvaluationContext; if (dynamicContext == null) { throw new ArgumentException("The context must be a DynamicContentEvaluationContext."); } if (dynamicContext.ToDate == default(DateTime)) { dynamicContext.ToDate = DateTime.UtcNow; } 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 = _expressionSerializer.DeserializeExpression <Func <IEvaluationContext, bool> >(publishing.ConditionExpression); if (condition(context)) { contentItemIds.AddRange(publishing.ContentItems.Select(x => x.DynamicContentItemId)); } } catch (Exception ex) { _logger.Error(ex); } } retVal.AddRange(_dynamicContentService.GetContentItemsByIds(contentItemIds.ToArray())); } return(retVal.ToArray()); }