Beispiel #1
0
        public ActionResult List(string articleId, int?page = 1)
        {
            try
            {
                if (string.IsNullOrEmpty(articleId))
                {
                    return(Json(new { code = 401, msg = "articleId不能为空" }));
                }

                CommentListQuery listModel = new CommentListQuery();
                listModel.PageIndex = Convert.ToInt32(page);
                listModel.PageSize  = 10;
                listModel.ArticleId = articleId;

                CommentListModelResult    result   = _commentService.GetPaged(listModel);
                StaticPagedList <Comment> pageList = new StaticPagedList <Comment>(result.List, listModel.PageIndex, listModel.PageSize, result.TotalCount);

                GetChildren(result.List.ToList());

                return(Json(new { code = 200, data = result.List, pageNumber = pageList.PageNumber, pageCount = pageList.PageCount }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogService.Instance.AddAsync(Level.Error, ex);
                return(Json(new { code = 500, msg = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        public CommentListModelResult GetPaged(CommentListQuery listModel)
        {
            CommentListModelResult result = new CommentListModelResult();

            result.List = new List <Comment>();

            StringBuilder builder = new StringBuilder("select * from Comment where Enable = 1 and parentId = 0");

            if (!string.IsNullOrEmpty(listModel.ArticleId))
            {
                builder.Append(" and ArticleId = ?");
            }

            if (string.IsNullOrEmpty(listModel.Order))
            {
                builder.Append(" order by createtime desc,CommentId asc");
            }

            object[] para = { listModel.ArticleId };

            DataTable dt = SQLiteHelper.ExecutePager(listModel.PageIndex, listModel.PageSize, builder.ToString(), para);

            foreach (DataRow item in dt.Rows)
            {
                result.List.Add(RowToModel(item));
            }

            StringBuilder countSql = new StringBuilder("select count(1) from Comment where Enable = 1 and parentId = 0");

            if (!string.IsNullOrEmpty(listModel.ArticleId))
            {
                countSql.Append(" and ArticleId = ?");
            }

            object countNum = SQLiteHelper.ExecuteScalar(countSql.ToString(), para);

            result.TotalCount = Convert.ToInt32(countNum);

            return(result);
        }