Beispiel #1
0
        public async Task <PagingResult <PostView> > GetPagingResultAsync(Guid topicId, PostResultType resultType = PostResultType.All, int currentPage = 1, int pageSize = 10, FilterType filter = FilterType.New)
        {
            SqlBuilder builder = new SqlBuilder();

            builder.AppendToEnd("from post_view where");
            // 屏蔽被禁言用户的帖子
            builder.AppendToEnd("person_is_delete = false and person_is_mute = false");
            // 只能查询已发布的贴子
            builder.AppendToEnd("and post_status = @post_status").AddParameter("post_status", PostStatus.Publish);
            // 添加结果类型
            switch (resultType)
            {
            case PostResultType.All:
                break;

            case PostResultType.Question:
                builder.AppendToEnd("and post_type = @postType").AddParameter("postType", PostType.Question);
                break;

            case PostResultType.Article:
                builder.AppendToEnd("and post_type = @postType").AddParameter("postType", PostType.Article);
                break;
            }

            // 添加话题
            if (topicId != Guid.Empty)
            {
                builder.AppendToEnd("and topic_id = @topicId").AddParameter("topicId", topicId);
            }
            // 过滤选项
            switch (filter)
            {
            case FilterType.Best:
                builder.AppendToEnd("and is_best = true");
                break;

            case FilterType.ZeroResponse:
                builder.AppendToEnd("and comment_num = 0");
                break;
            }
            // 总数查询
            SqlBuilder countQuery = builder.Clone() as SqlBuilder;

            countQuery.InsertToStart("select count(*)");
            long count = await this.connection.ScalarAsync <long>(countQuery);

            // 添加排序
            builder.InsertToStart("select *");
            if (filter == FilterType.Popular)
            {
                builder.AppendToEnd("order by is_top desc,comment_num desc,create_time desc");
            }
            else
            {
                builder.AppendToEnd("order by is_top desc,create_time desc");
            }
            // 添加分页
            builder.SetPaging(currentPage, pageSize);
            List <PostView> posts = await this.connection.SelectAsync <PostView>(builder);

            return(new PagingResult <PostView>(currentPage, pageSize, count, posts));
        }
Beispiel #2
0
        /// <summary>
        /// 获取用户公开发表的帖子
        /// </summary>
        public async Task <PagingResult <PostView> > GetPagingResultAsync(PersonView person, PostResultType resultType, int currentPage)
        {
            using (var work = this.dbFactory.StartWork())
            {
                var config = await work.Config.GetPageConfigAsync();

                return(await work.PostView.GetPagingResultAsync(person, resultType, currentPage, config.PageSize));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获取用户公开发表的的帖子
        /// </summary>
        public async Task <PagingResult <PostView> > GetPagingResultAsync(PersonView person, PostResultType resultType, int currentPage = 1, int pageSize = 10)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }
            SqlBuilder builder = new SqlBuilder();

            builder.AppendToEnd("from post_view where person_is_mute = false and person_is_delete = false");
            builder.AppendToEnd("and post_status = @postStatus").AddParameter("postStatus", PostStatus.Publish);
            builder.AppendToEnd("and person_id =@personId").AddParameter("personId", person.Id);
            // 添加结果类型
            switch (resultType)
            {
            case PostResultType.Question:
                builder.AppendToEnd("and post_type = @postType").AddParameter("postType", PostType.Question);
                break;

            case PostResultType.Article:
                builder.AppendToEnd("and post_type = @postType").AddParameter("postType", PostType.Article);
                break;
            }
            // 计算总数
            SqlBuilder countBuilder = builder.Clone() as SqlBuilder;

            countBuilder.InsertToStart("select count(*)");
            long count = await this.connection.ScalarAsync <long>(countBuilder);

            // 获取记录
            builder.InsertToStart("select *");
            builder.AppendToEnd("order by post_view.is_top,post_view.create_time desc");
            builder.SetPaging(currentPage, pageSize);
            List <PostView> posts = await this.connection.SelectAsync <PostView>(builder);

            return(new PagingResult <PostView>(currentPage, pageSize, count, posts));
        }
Beispiel #4
0
        /// <summary>
        /// 获取分页结果
        /// </summary>
        public async Task <PagingResult <PostView> > GetPagingResultAsync(Guid topicId, PostResultType resultType = PostResultType.All, int currentPage = 1, FilterType filter = FilterType.New)
        {
            using (var work = this.dbFactory.StartWork())
            {
                var config = await work.Config.GetPageConfigAsync();

                return(await work.PostView.GetPagingResultAsync(topicId, resultType, currentPage, config.PageSize, filter));
            }
        }