private void SearchFolders(coreModel.MarketingSearchCriteria criteria, coreModel.MarketingSearchResult result) { using (var repository = _repositoryFactory()) { var query = repository.Folders.Where(x => x.ParentFolderId == criteria.FolderId); var folderIds = query.Select(x => x.Id).ToArray(); result.ContentFolders = new List <coreModel.DynamicContentFolder>(); foreach (var folderId in folderIds) { var folder = repository.GetContentFolderById(folderId); result.ContentFolders.Add(folder.ToCoreModel()); } // Populate folder for all found places and items if (criteria.FolderId != null) { var searchedFolder = repository.GetContentFolderById(criteria.FolderId); if (searchedFolder != null) { var hasfolderItems = result.ContentPlaces.OfType <coreModel.IsHasFolder>().Concat(result.ContentItems); foreach (var hasfolderItem in hasfolderItems) { hasfolderItem.Folder = searchedFolder.ToCoreModel(); } } } } }
private void SearchPromotions(coreModel.MarketingSearchCriteria criteria, coreModel.MarketingSearchResult result) { var promotions = new List<coreModel.Promotion>(); var totalCount = 0; using (var repository = _repositoryFactory()) { var query = repository.Promotions; if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Description.Contains(criteria.Keyword)); } promotions = query.OrderBy(x => x.Id) .Skip(criteria.Start) .Take(criteria.Count) .ToArray() .Select(x => x.ToCoreModel()) .ToList(); totalCount = query.Count(); } promotions.AddRange(_customPromotionManager.Promotions.Skip(criteria.Start).Take(criteria.Count)); totalCount += _customPromotionManager.Promotions.Count(); result.Promotions = promotions; result.TotalCount += totalCount; }
public coreModel.MarketingSearchResult SearchResources(coreModel.MarketingSearchCriteria criteria) { var retVal = new coreModel.MarketingSearchResult(); var count = criteria.Count; if ((criteria.ResponseGroup & coreModel.SearchResponseGroup.WithPromotions) == coreModel.SearchResponseGroup.WithPromotions) { SearchPromotions(criteria, retVal); criteria.Count -= retVal.Promotions.Count(); } if ((criteria.ResponseGroup & coreModel.SearchResponseGroup.WithContentItems) == coreModel.SearchResponseGroup.WithContentItems) { SearchContentItems(criteria, retVal); criteria.Count -= retVal.ContentItems.Count(); } if ((criteria.ResponseGroup & coreModel.SearchResponseGroup.WithContentPlaces) == coreModel.SearchResponseGroup.WithContentPlaces) { SearchContentPlaces(criteria, retVal); criteria.Count -= retVal.ContentPlaces.Count(); } if ((criteria.ResponseGroup & coreModel.SearchResponseGroup.WithContentPublications) == coreModel.SearchResponseGroup.WithContentPublications) { SearchContentPublications(criteria, retVal); criteria.Count -= retVal.ContentPublications.Count(); } if ((criteria.ResponseGroup & coreModel.SearchResponseGroup.WithFolders) == coreModel.SearchResponseGroup.WithFolders) { SearchFolders(criteria, retVal); } return(retVal); }
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(); } }
public IHttpActionResult Search([ModelBinder(typeof(MarketingSearchCriteriaBinder))] coreModel.MarketingSearchCriteria criteria) { var retVal = new webModel.MarketingSearchResult(); var coreResult = _marketingSearchService.SearchResources(criteria); retVal.Promotions = coreResult.Promotions.Select(x => x.ToWebModel()).ToList(); retVal.ContentPlaces = coreResult.ContentPlaces.Select(x => x.ToWebModel()).ToList(); retVal.ContentItems = coreResult.ContentItems.Select(x => x.ToWebModel()).ToList(); retVal.ContentPublications = coreResult.ContentPublications.Select(x => x.ToWebModel()).ToList(); retVal.ContentFolders = coreResult.ContentFolders.Select(x => x.ToWebModel()).ToList(); retVal.TotalCount = coreResult.TotalCount; return(Ok(retVal)); }
private void SearchContentPublications(coreModel.MarketingSearchCriteria criteria, coreModel.MarketingSearchResult result) { using (var repository = _repositoryFactory()) { var query = repository.PublishingGroups; result.TotalCount += query.Count(); var ids = query.OrderBy(x => x.Id) .Select(x => x.Id) .Skip(criteria.Start) .Take(criteria.Count).ToArray(); result.ContentPublications = ids.Select(x => _dynamicContentService.GetPublicationById(x)).ToList(); } }
private void SearchContentItems(coreModel.MarketingSearchCriteria criteria, coreModel.MarketingSearchResult result) { using (var repository = _repositoryFactory()) { var query = repository.Items.Include(x => x.PropertyValues).Where(x => x.FolderId == criteria.FolderId); result.TotalCount += query.Count(); result.ContentItems = query.OrderBy(x => x.Id) .Skip(criteria.Start) .Take(criteria.Count) .ToArray() .Select(x => x.ToCoreModel()) .ToList(); } }
private void SearchPromotions(coreModel.MarketingSearchCriteria criteria, coreModel.MarketingSearchResult result) { var promotions = new List <coreModel.Promotion>(); var totalCount = 0; using (var repository = _repositoryFactory()) { promotions = repository.Promotions.OrderBy(x => x.Id) .Skip(criteria.Start) .Take(criteria.Count) .ToArray() .Select(x => x.ToCoreModel()) .ToList(); totalCount = repository.Promotions.Count(); } promotions.AddRange(_customPromotionManager.Promotions.Skip(criteria.Start).Take(criteria.Count)); totalCount += _customPromotionManager.Promotions.Count(); result.Promotions = promotions; result.TotalCount += totalCount; }
public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext) { if (bindingContext.ModelType != typeof(MarketingSearchCriteria)) { return false; } var qs = HttpUtility.ParseQueryString(actionContext.Request.RequestUri.Query as string); var result = new MarketingSearchCriteria(); var respGroup = qs["respGroup"].EmptyToNull(); result.ResponseGroup = SearchResponseGroup.Full; if (respGroup != null) { result.ResponseGroup = (SearchResponseGroup)Enum.Parse(typeof(SearchResponseGroup), respGroup, true); } result.FolderId = qs["folder"]; result.Keyword = qs["q"].EmptyToNull(); result.Count = qs["count"].TryParse(20); result.Start = qs["start"].TryParse(0); bindingContext.Model = result; return true; }