Beispiel #1
0
        /// <summary>
        /// 加载个人评论(个人中心:我的跟帖)
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public Stream LoadUserContent(string userId, string page, string pagesize)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            // 设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            // 根据条件获得评论
            List <CommentInfo> cmtLst = DataAccess_News.Comments_SelectPaged(userId, page, pagesize);

            // 在评论里加上作者、发表时间、以及文章标题
            List <CommentInfoApp> cmtLst2 = new List <CommentInfoApp>();

            if (cmtLst != null)
            {
                for (int i = 0; i < cmtLst.Count; i++)
                {
                    var item    = cmtLst[i];
                    var infoApp = new CommentInfoApp();
                    infoApp.cmt_content      = item.cmt_content;
                    infoApp.cmt_id           = item.cmt_id;
                    infoApp.cmt_sourceId     = item.cmt_sourceId;
                    infoApp.cmt_sourceType   = item.cmt_sourceType;
                    infoApp.cmt_uid          = item.cmt_uid;
                    infoApp.cmt_sourceCateId = item.cmt_sourceCateId;

                    int catId = 0;
                    if (!int.TryParse(item.cmt_sourceCateId, out catId))
                    {
                        continue;
                    }

                    var cate = CacheMarker.GetNewsCatesBycat_id(catId.ToString());
                    if (cate == null)
                    {
                        continue;
                    }
                    NewsInfo news = CacheMarker.News_Selectbyn_gid(item.cmt_sourceId, "News_" + cate.cat_tableIndex.ToString());
                    if (news != null)
                    {
                        infoApp.n_authors = news.n_authors;
                        infoApp.n_date    = news.n_date;
                        infoApp.n_title   = news.n_title;
                    }

                    cmtLst2.Add(infoApp);
                }
            }
            var jsonSerialiser = new JavaScriptSerializer();

            json = "{\"list\":" + jsonSerialiser.Serialize(cmtLst2) + "}";
            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Beispiel #2
0
        /// <summary>
        /// 获得某文章的所有评论(最新评论在前面)
        /// </summary>
        /// <param name="sourceId">w文章ID</param>
        /// <param name="page">第几页评论</param>
        /// <param name="limit">每页最大评论数</param>
        /// <returns></returns>
        public Stream Comments_SelectPaged(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

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

            int rowcount = 0;
            List <CommentInfo> comments = DataAccess_News.Comments_SelectPaged(sourceId, page, limit, out rowcount);

            // 获取评论cmt_uid集合
            List <string> cmt_Uids = new List <string>();

            comments.ForEach(m =>
            {
                cmt_Uids.Add(m.cmt_uid);
                if (!string.IsNullOrEmpty(m.cmt_parentIds))
                {
                    cmt_Uids.AddRange(m.cmt_parentIds.Split(','));
                }
            });
            cmt_Uids = cmt_Uids.Distinct().ToList();

            var jsonSerialiser             = new JavaScriptSerializer();
            var json                       = "";
            List <CommentInfo> commentList = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmt_Uids.ToArray());

            foreach (var 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);                                    // 存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime);                                   // 存放友好时间
            }
            json = jsonSerialiser.Serialize(commentList);
            json = "{\"list\":" + json + ",\"ids\":" + jsonSerialiser.Serialize(comments) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Beispiel #3
0
        /// <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)));
        }