public IEnumerable<ContentItem> GetFilteredNotificationBatches(string keywords, DateTime? fromDate, DateTime? toDate, NotificationBatchSortBy sortBy)
        {
            var pager = new Pager(_siteService.GetSiteSettings(), new PagerParameters());
            var searchSettingsPart = _orchardServices.WorkContext.CurrentSite.As<SearchSettingsPart>();

            IEnumerable<ISearchHit> searchHits = new PageOfItems<ISearchHit>(new ISearchHit[] { });

            searchHits = _searchService.Query(keywords, pager.Page, pager.PageSize,
                                              _orchardServices.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
                                              searchSettingsPart.SearchIndex,
                                              searchSettingsPart.SearchedFields,
                                              searchHit => searchHit);

            var notificationBatchItems = _contentManager
                .Query(VersionOptions.Latest, Constants.NotificationBatchContentType)
                .ForContentItems(searchHits.Select(hit => hit.ContentItemId));

            if (fromDate != null && toDate != null)
            {
                notificationBatchItems = notificationBatchItems
                    .Where<CommonPartRecord>(record => record.CreatedUtc >= fromDate.Value && record.CreatedUtc <= toDate.Value);
            }

            switch (sortBy)
            {
                case NotificationBatchSortBy.DateSent: notificationBatchItems = notificationBatchItems
                    .OrderByDescending<CommonPartRecord>(record => record.PublishedUtc);
                    break;
                case NotificationBatchSortBy.Title: notificationBatchItems = notificationBatchItems
                    .OrderBy<TitlePartRecord>(record => record.Title);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("sortBy");
            }

            return notificationBatchItems.List();
        }
示例#2
0
        public IEnumerable <ContentItem> GetFilteredNotificationBatches(string keywords, DateTime?fromDate, DateTime?toDate, NotificationBatchSortBy sortBy)
        {
            var pager = new Pager(_siteService.GetSiteSettings(), new PagerParameters());
            var searchSettingsPart = _orchardServices.WorkContext.CurrentSite.As <SearchSettingsPart>();

            IEnumerable <ISearchHit> searchHits = new PageOfItems <ISearchHit>(new ISearchHit[] { });

            searchHits = _searchService.Query(keywords, pager.Page, pager.PageSize,
                                              _orchardServices.WorkContext.CurrentSite.As <SearchSettingsPart>().Record.FilterCulture,
                                              searchSettingsPart.SearchIndex,
                                              searchSettingsPart.SearchedFields,
                                              searchHit => searchHit);

            var notificationBatchItems = _contentManager
                                         .Query(VersionOptions.Latest, Constants.NotificationBatchContentType)
                                         .ForContentItems(searchHits.Select(hit => hit.ContentItemId));

            if (fromDate != null && toDate != null)
            {
                notificationBatchItems = notificationBatchItems
                                         .Where <CommonPartRecord>(record => record.CreatedUtc >= fromDate.Value && record.CreatedUtc <= toDate.Value);
            }

            switch (sortBy)
            {
            case NotificationBatchSortBy.DateSent: notificationBatchItems = notificationBatchItems
                                                                            .OrderByDescending <CommonPartRecord>(record => record.PublishedUtc);
                break;

            case NotificationBatchSortBy.Title: notificationBatchItems = notificationBatchItems
                                                                         .OrderBy <TitlePartRecord>(record => record.Title);
                break;

            default:
                throw new ArgumentOutOfRangeException("sortBy");
            }

            return(notificationBatchItems.List());
        }