public ActionResult PostList(int pageIndex, int pageSize, ItemQueryFilter filter)
        {
            if (filter == null)
            {
                filter = new ItemQueryFilter
                             {
                                 MaxPublishAt = DateTimeOffset.Now.AddMonths(1).AsMinutes(),
                                 MinPublishAt = DateTimeOffset.Now.AsMinutes(),
                                 Status = ItemStatus.Scheduled
                             };
            }
            IPagedResult<PostDto> model = this.postService.GetPosts(1, 5, filter);

            return this.View(model);
        }
        public IList<CommentDto> GetRecentApprovedComments(int maxNumberOfComments, ItemQueryFilter filters)
        {
            IRavenQueryable<PostCommentsCreationDateIndex.ReduceResult> query = this.Session.Query<PostCommentsCreationDateIndex.ReduceResult, PostCommentsCreationDateIndex>();

            if (filters != null && filters.Status.HasValue)
            {
                query.Where(x => x.Status == filters.Status);
            }

            if (filters != null && filters.MinPublishAt.HasValue)
            {
                query.Where(x => x.ItemPublishedAt > filters.MaxPublishAt);
            }

            if (filters != null && filters.MaxPublishAt.HasValue)
            {
                query.Where(x => x.ItemPublishedAt < filters.MaxPublishAt);
            }

            List<PostCommentsCreationDateIndex.ReduceResult> data = query.ThenByDescending(x => x.CreatedAt)
                                                                         .AsProjection<PostCommentsCreationDateIndex.ReduceResult>()
                                                                         .Take(maxNumberOfComments)
                                                                         .ToList();

            IList<CommentDto> list = new List<CommentDto>();

            foreach (PostCommentsCreationDateIndex.ReduceResult commentIdentifier in data)
            {
                ItemComments comments = this.Session.Load<ItemComments>(commentIdentifier.PostCommentsId);
                Comment comment = comments.Approved.FirstOrDefault(x => x.Id == commentIdentifier.CommentId);
                Item item = this.Session.Load<Post>(commentIdentifier.ItemId);

                CommentDto c = comment.MapTo<CommentDto>();
                c.ItemInfo = item.MapTo<ItemBaseInfo>();

                list.Add(c);
            }

            return list;
        }
Пример #3
0
        public IPagedResult<PageDto> GetPages(int pageIndex, int pageSize, ItemQueryFilter filters)
        {
            if (pageIndex < 1)
            {
                throw new ArgumentException("The page index must be greater than 0", "pageIndex");
            }

            if (pageSize < 1)
            {
                throw new ArgumentException("The page size must be greater than 0", "pageSize");
            }

            if (filters == null)
            {
                filters = new ItemQueryFilter();
                filters.MaxPublishAt = DateTime.Now;
                filters.Status = ItemStatus.Published;
            }

            CancelEventArgsWithOneParameter<Tuple<int, int, ItemQueryFilter>, IPagedResult<PageDto>> e = new CancelEventArgsWithOneParameter<Tuple<int, int, ItemQueryFilter>, IPagedResult<PageDto>>(new Tuple<int, int, ItemQueryFilter>(pageIndex, pageSize, filters), null);

            this.PagesRetrievingWithFilters.Raise(this, e);

            if (e.Cancel)
            {
                this.logger.DebugAsync("The result of the method 'GetPages' is overridden by the event 'PagesRetrievingWithFilters'.");
                return e.Result;
            }

            IPagedResult<PageDto> result = this.pageDataService.GetPages(pageIndex, pageSize, filters);

            this.PagesRetrievedWithFilters.Raise(this, new GenericEventArgs<IPagedResult<PageDto>>(result));

            return result;
        }
        public IPagedResult<PageDto> GetPages(int pageIndex, int pageSize, ItemQueryFilter filter)
        {
            if (pageIndex < 1)
            {
                throw new ArgumentException("The page index must be greater than 0", "pageIndex");
            }

            if (pageSize < 1)
            {
                throw new ArgumentException("The page size must be greater than 0", "pageSize");
            }

            RavenQueryStatistics stats;

            return this.Session.Query<Page>()
                       .Statistics(out stats)
                       .ApplyFilterItem(filter)
                       .OrderByDescending(post => post.PublishAt)
                       .ToPagedResult<Page, PageDto>(pageIndex, pageSize, stats);
        }
        public IPagedResult<PostDto> Search(string term, int pageIndex, int pageSize, ItemQueryFilter filters)
        {
            RavenQueryStatistics stats;

            return this.Session.Query<PostFullTextIndex.ReduceResult, PostFullTextIndex>()
                       .Customize(x => x.Highlight("SearchQuery", 128, 1, "Results"))
                       .Search(x => x.SearchQuery, term)
                       .OrderByDescending(post => post.PublishDate)
                       .Statistics(out stats)
                       .As<Post>()
                       .ApplyFilterItem(filters)
                       .ToPagedResult<Post, PostDto>(pageIndex, pageSize, stats);
        }
        public IPagedResult<PostDto> GetPostsByTag(int pageIndex, int pageSize, string tag, ItemQueryFilter filters)
        {
            if (pageIndex < 1)
            {
                throw new ArgumentException("The page index must be greater than 0", "pageIndex");
            }

            if (pageSize < 1)
            {
                throw new ArgumentException("The page size must be greater than 0", "pageSize");
            }

            if (string.IsNullOrEmpty(tag))
            {
                throw new ArgumentException("The tag must contains a valid value.", "tag");
            }

            RavenQueryStatistics stats;

            return this.Session.Query<Post>()
                       .Statistics(out stats)
                       .ApplyFilterItem(filters)
                       .Where(post => post.Tags.Any(postTag => postTag == tag))
                       .OrderByDescending(post => post.PublishAt)
                       .ToPagedResult<Post, PostDto>(pageIndex, pageSize, stats);
        }
        public IPagedResult<PostDto> GetPostsByDate(int pageIndex, int pageSize, int year, int? month, int? day, ItemQueryFilter filters)
        {
            if (pageIndex < 1)
            {
                throw new ArgumentException("The page index must be greater than 0", "pageIndex");
            }

            if (pageSize < 1)
            {
                throw new ArgumentException("The page size must be greater than 0", "pageSize");
            }

            if (year < 1700)
            {
                throw new ArgumentException("The year value must be greater than 1700. Internet did not exist in 1700!", "year");
            }

            if (month.HasValue && (month.Value < 1 || month.Value > 12))
            {
                throw new ArgumentException("The month value must be greater than 0 and lesser than 12", "month");
            }

            if (day.HasValue && (day.Value < 1 || day.Value > 31))
            {
                throw new ArgumentException("The day value must be greater than 0 and lesser than 31", "month");
            }

            RavenQueryStatistics stats;

            IQueryable<Post> query = this.Session.Query<Post>()
                                         .Statistics(out stats)
                                         .Where(post => post.PublishAt.Year == year)
                                         .ApplyFilterItem(filters);

            if (month.HasValue)
            {
                query = query.Where(post => post.PublishAt.Month == month.Value);
            }

            if (day.HasValue)
            {
                query = query.Where(post => post.PublishAt.Day == day.Value);
            }

            return query
                .OrderByDescending(post => post.PublishAt)
                .ToPagedResult<Post, PostDto>(pageIndex, pageSize, stats);
        }
        public IPagedResult<PostDto> GetPostsByCategory(int pageIndex, int pageSize, string categoryName, ItemQueryFilter filters)
        {
            if (pageIndex < 1)
            {
                throw new ArgumentException("The page index must be greater than 0.", "pageIndex");
            }

            if (pageSize < 1)
            {
                throw new ArgumentException("The page size must be greater than 0.", "pageSize");
            }

            if (string.IsNullOrEmpty(categoryName))
            {
                throw new ArgumentException("The category name must contains a valid value.", "categoryName");
            }

            RavenQueryStatistics stats;

            return this.Session.Query<Post>()
                       .Statistics(out stats)
                       .ApplyFilterItem(filters)
                       .Where(post => post.Categories.Any(postCategory => postCategory == categoryName))
                       .OrderByDescending(post => post.PublishAt)
                       .ToPagedResult<Post, PostDto>(pageIndex, pageSize, stats);
        }