Exemplo n.º 1
0
        public int GetArticlesCountByColumnId(int columnId)
        {
            if (columnId <= 0)
            {
                return(columnId);
            }
            var columnIds = ColumnRepository.Fetch(d => d.TreePath.Contains("," + columnId + ","))
                            .Select(d => d.Id).ToList();

            return(TomeltServices.ContentManager.Query(VersionOptions.Latest).Where <ArticlePartRecord>(d => columnIds.Contains(d.ColumnPartRecordId)).Count());
        }
Exemplo n.º 2
0
        public IEnumerable <ContentItem> GetArticlesPro(EditArticlePartViewModel search)
        {
            //内容状态
            VersionOptions versionOptions;

            switch (search.contentStatus)
            {
            case "Published":
                versionOptions = VersionOptions.Published;
                break;

            case "Draft":
                versionOptions = VersionOptions.Draft;
                break;

            case "AllVersions":
                versionOptions = VersionOptions.AllVersions;
                break;

            default:
                versionOptions = VersionOptions.Latest;
                break;
            }
            var query = TomeltServices.ContentManager.Query(versionOptions, GetCreatableTypes(false).Select(ctd => ctd.Name).ToArray());

            query = query.ForType(ContentTypeName);
            if (search.ColumnPartRecordId > 0)
            {
                var columnIds = ColumnRepository.Fetch(d => d.TreePath.Contains("," + search.ColumnPartRecordId + ","))
                                .Select(d => d.Id).ToList();
                query = query.Where <ArticlePartRecord>(d => columnIds.Contains(d.ColumnPartRecordId));
            }
            if (!string.IsNullOrWhiteSpace(search.Title))
            {
                query = query.Where <TitlePartRecord>(d => d.Title.Contains(search.Title));
            }


            //升降序
            switch (search.order)
            {
            case "asc":
                query = query.OrderBy <CommonPartRecord>(cr => cr.CreatedUtc);
                break;

            default:
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.CreatedUtc);
                break;
            }
            //查看自己的数据
            if (search.contentStatus == "Owner")
            {
                query = query.Where <CommonPartRecord>(cr => cr.OwnerId == TomeltServices.WorkContext.CurrentUser.Id);
            }
            search.total = query.Count();
            //分页
            int pageSize      = search.rows ?? 10;
            var maxPagedCount = SiteService.GetSiteSettings().MaxPagedCount;

            if (maxPagedCount > 0 && pageSize > maxPagedCount)
            {
                pageSize = maxPagedCount;
            }
            int page = search.page ?? 1;

            return(query.Slice((page - 1) * pageSize, pageSize).ToList());
        }