Exemplo n.º 1
0
        /// <summary>
        ///
        /// 加载评论
        /// </summary>
        /// <param name="context"></param>
        private void LoadComment(HttpContext context)
        {
            int bookId = int.Parse(context.Request["bookId"]);
            List <Model.BookComment> commentList   = new BLL.BookComment().GetModelList(" bookId=" + bookId);
            List <CommentViewModel>  viewModelList = new List <CommentViewModel>();

            for (int i = 0; i < commentList.Count; i++)
            {
                CommentViewModel viewModel = new CommentViewModel();
                viewModel.Msg = Common.WebHelper.HtmlDecode(commentList[i].Msg);
                TimeSpan ts = DateTime.Now - commentList[i].CreateDateTime;
                viewModel.CreateDateTime = Common.WebHelper.GetTimeSpan(ts);
                viewModelList.Add(viewModel);
            }

            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            context.Response.Write(js.Serialize(viewModelList));
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];

            if (action == "add")
            {
                Model.BookComment entity = new Model.BookComment();
                entity.BookId         = Convert.ToInt32(context.Request["bookId"]);
                entity.Msg            = context.Request["msg"];
                entity.CreateDateTime = DateTime.Now;
                BLL.BookComment bll = new BLL.BookComment();
                if (bll.Add(entity) > 0)
                {
                    context.Response.Write("ok");
                }
                else
                {
                    context.Response.Write("no");
                }
            }
            else if (action == "load")//加载评论
            {
                int                      bookId   = Convert.ToInt32(context.Request["bookId"]);
                BLL.BookComment          bll      = new BLL.BookComment();
                List <Model.BookComment> comments = bll.GetModelList(" bookId =" + bookId);
                //进行时间运算
                List <CommentViewModel> viewList = new List <CommentViewModel>();
                foreach (var entity in comments)
                {
                    CommentViewModel view = new CommentViewModel();
                    view.Msg            = entity.Msg;
                    view.CreateDateTime = Common.WebCommon.GetTimeSpan(DateTime.Now - entity.CreateDateTime);
                    viewList.Add(view);
                }
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
                context.Response.Write(js.Serialize(viewList.ToArray()));
            }
        }