public virtual Task <IPagedList <ArticleInfoView> > GetArticlesAsync(MaterialsShowOptions options) { Func <IQueryable <Material>, IOrderedQueryable <Material> > orderBy; if (options.orderType == OrderType.PublishDate) { orderBy = x => x.OrderByDescending(y => y.PublishDate); } else { orderBy = x => x.OrderByDescending(y => y.SortNumber); } IQueryable <Material> query = db.Materials; if (!options.ShowHidden) { query = query.Where(x => !x.IsHidden); } if (!options.ShowDeleted) { query = query.Where(x => x.DeletedDate == null); } return(query.GetPagedListAsync( x => new ArticleInfoView { Id = x.Id, Name = x.Name, Title = x.Title, Description = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, PublishDate = x.PublishDate, CategoryName = x.Category.Name, SortNumber = x.SortNumber, IsHidden = x.IsHidden, DeletedDate = x.DeletedDate, IsCommentsBlocked = x.IsCommentsBlocked }, x => x.CategoryId == options.CategoryId, orderBy, options.Page, options.PageSize)); }
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); }
public virtual Task <IPagedList <TopicInfoView> > GetThreadAsync(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); } return(query.GetPagedListAsync( x => new TopicInfoView { Id = x.Id, Title = x.Title, SubTitle = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, LastCommentId = x.LastCommentId, LastCommentPublishDate = x.LastCommentId.HasValue ? (DateTime?)x.LastComment.PublishDate : null, CategoryName = x.Category.Name, LastCommentAuthorName = x.LastComment.Author.UserName, LastCommentAuthorAvatar = x.LastComment.Author.Avatar, IsCommentsBlocked = x.IsCommentsBlocked, IsHidden = x.IsHidden, DeletedDate = x.DeletedDate }, x => x.CategoryId == options.CategoryId, x => x.OrderByDescending(y => y.LastActivity), options.Page, options.PageSize)); }
public virtual 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); } return(query.GetPagedListAsync( x => new PostView { Id = x.Id, Title = x.Title, Preview = x.Preview, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorLink = x.Author.Link, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, CategoryName = x.Category.Name, HasMoreText = x.Text.Length != x.Preview.Length, IsCommentsBlocked = x.IsCommentsBlocked, IsHidden = x.IsHidden, DeletedDate = x.DeletedDate }, x => x.CategoryId == options.CategoryId, x => x.OrderByDescending(y => y.PublishDate), options.Page, options.PageSize)); }