Пример #1
0
        public virtual async Task <IPagedList <PostView> > GetPostsFromMultiCategoriesAsync(
            MaterialsMultiCatShowOptions options)
        {
            var rez = await db.MaterialsVisible.GetPagedListAsync(
                x => new PostView
            {
                Id                = x.Id,
                Title             = x.Title,
                Preview           = x.Text,
                CommentsCount     = x.CommentsCount,
                AuthorName        = x.Author.UserName,
                AuthorLink        = x.Author.Link,
                AuthorAvatar      = x.Author.Avatar,
                PublishDate       = x.PublishDate,
                CategoryName      = x.Category.Name,
                CategoryTitle     = x.Category.Title,
                IsCommentsBlocked = x.IsCommentsBlocked
            },
                x => options.CategoriesIds.Contains(x.CategoryId),
                x => x.OrderByDescending(y => y.PublishDate),
                options.Page,
                options.PageSize);

            foreach (var postView in rez.Items)
            {
                var textLength = postView.Preview.Length;
                postView.Preview =
                    MakePreview.HtmlFirstImage(new HtmlParser().Parse(postView.Preview), options.PreviewSize);
                postView.HasMoreText = postView.Preview.Length != textLength;
            }

            return(rez);
        }
Пример #2
0
        public virtual async Task <IPagedList <PostView> > GetPostsAsync(MaterialsShowOptions options)
        {
            IQueryable <Material> query = db.Materials;

            if (!options.ShowHidden)
            {
                query = query.Where(x => !x.IsHidden);
            }

            if (!options.ShowDeleted)
            {
                query = query.Where(x => x.DeletedDate == null);
            }

            var rez = await query.GetPagedListAsync(
                x => new PostView
            {
                Id                = x.Id,
                Title             = x.Title,
                Preview           = x.Text,
                CommentsCount     = x.CommentsCount,
                AuthorName        = x.Author.UserName,
                AuthorLink        = x.Author.Link,
                AuthorAvatar      = x.Author.Avatar,
                PublishDate       = x.PublishDate,
                CategoryName      = x.Category.Name,
                IsCommentsBlocked = x.IsCommentsBlocked,
                IsHidden          = x.IsHidden,
                DeletedDate       = x.DeletedDate
            },
                x => x.CategoryId == options.CategoryId,
                x => x.OrderByDescending(y => y.PublishDate),
                options.Page,
                options.PageSize);

            foreach (var postView in rez.Items)
            {
                var textLength = postView.Preview.Length;
                postView.Preview =
                    MakePreview.HtmlFirstImage(new HtmlParser().Parse(postView.Preview),
                                               blogOptions.CurrentValue.PreviewLength);
                postView.HasMoreText = postView.Preview.Length != textLength;
            }

            return(rez);
        }