コード例 #1
0
ファイル: DataAccess_News.cs プロジェクト: Violet-Liu/Learn
        /// <summary>
        /// 获得某文章的最新评论
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="rowcount"></param>
        /// <returns></returns>
        public static List <CommentInfo> Comments_SelectPaged(string sourceId, string page, string limit,
                                                              out int rowcount)
        {
            page  = (int.Parse(page) < 1) ? "1" : page;
            limit = (int.Parse(limit) > 30) ? "30" : limit;

            CommentsSearchInfo search = new CommentsSearchInfo();

            search.cmt_sourceId = sourceId.ToSafetyStr();
            search.cmt_status   = 1;
            search.page         = int.Parse(page);
            search.pagesize     = Int32.Parse(limit);

            using (var access = new DataAccess_QzNews(Constants.QZNewSite_News_Db_Key))
            {
                return(access.Comments_SelectPaged(search.columns, search.ToWhereString(), search.DefOrder, search.page,
                                                   search.pagesize, true, out rowcount));
            }
        }
コード例 #2
0
ファイル: DataAccess_News.cs プロジェクト: Violet-Liu/Learn
        /// <summary>
        /// 加载个人评论
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public static List <CommentInfo> Comments_SelectPaged(string userId, string page, string pagesize)
        {
            page     = (int.Parse(page) < 1) ? "1" : page;
            pagesize = (int.Parse(pagesize) > 30) ? "30" : pagesize;

            // 设置获取条件
            CommentsSearchInfo search = new CommentsSearchInfo();

            search.cmt_status       = 1;
            search.page             = int.Parse(page);
            search.pagesize         = int.Parse(pagesize);
            search.cmt_createUserID = int.Parse(userId);

            // 根据条件获得评论
            int rowcount = 0;

            using (var access = new DataAccess_QzNews(Constants.QZNewSite_News_Db_Key))
            {
                // 获得评论
                return(access.Comments_SelectPaged(search.columns, search.ToWhereString(), search.DefOrder, search.page, search.pagesize, false, out rowcount));
            }
        }
コード例 #3
0
ファイル: News.svc.cs プロジェクト: Violet-Liu/Learn
        /// <summary>
        /// 获得某文章的所有评论(最新接口)
        /// </summary>
        /// <param name="sourceId">文章Id</param>
        /// <param name="page">评论所在的页码</param>
        /// <param name="limit">页最大评论数</param>
        /// <returns></returns>
        public Stream Comments_SelectPaged2(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            // 设置评论搜索条件
            CommentsSearchInfo search = new CommentsSearchInfo();

            search.cmt_sourceId = sourceId.ToSafetyStr();
            search.cmt_status   = 1;
            search.page         = int.Parse(page);
            search.pagesize     = int.Parse(limit);

            // 获取评论
            int rowcount = 0;
            List <CommentInfo> comments = DataAccess_News.Comments_SelectPaged(search.columns, search.ToWhereString(), search.DefOrder,
                                                                               search.page, search.pagesize, true, out rowcount);


            // 评论uid集合
            List <string> cmt_uids = new List <string>();

            foreach (var cmt in comments)
            {
                cmt_uids.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmt_uids.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmt_uids = cmt_uids.Distinct().ToList();

            var jsonSerializer = new JavaScriptSerializer();
            var json           = "";

            // 获取所有评论uid的评论
            List <CommentInfo> commentList = null;

            commentList = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmt_uids.ToArray());
            foreach (CommentInfo comment in commentList)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n"); // 解析编码后的危险字符
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);                                    //存放用户头像
            }
            json = jsonSerializer.Serialize(comments);

            /*
             * 组装成网易盖楼形式
             */
            int idCount = comments.Count;   // 楼层数
            List <List <CommentInfo> > newPosts = new List <List <CommentInfo> >();

            for (int index = 0; index < idCount; index++)
            {
                string        cmt_parentIds = comments[index].cmt_parentIds; // 获取所有父楼层Id
                List <string> idList        = new List <string>();           // 所有楼层id列表
                if (!string.IsNullOrEmpty(cmt_parentIds))
                {
                    idList.AddRange(cmt_parentIds.Split(','));
                }
                // 加上主楼
                idList.Add(comments[index].cmt_uid);

                Dictionary <string, CommentInfo> cmt = commentList.ToDictionary(a => a.cmt_uid);
                List <CommentInfo> result            = new List <CommentInfo>();
                CommentInfo        info = null;
                for (int idIndex = 0; idIndex < idList.Count; idIndex++)
                {
                    if (!cmt.TryGetValue(idList[idIndex], out info))
                    {
                        continue;
                    }
                    result.Add(info);
                }
                newPosts.Add(result);
            }
            json = "{\"list\":" + jsonSerializer.Serialize(newPosts) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }