public ActionResult GetList(int?page = 1, int pageSize = 10) { try { CommentInfoListQuery listModel = new CommentInfoListQuery(); listModel.PageIndex = Convert.ToInt32(page); listModel.PageSize = pageSize; CommentInfoListModelResult result = _commentService.GetInfoPaged(listModel); PagedResponse <CommentInfo> res = new PagedResponse <CommentInfo>() { List = result.List, CurrentPage = page.Value, TotalCount = result.TotalCount, PageSize = listModel.PageSize }; return(Json(new { code = 200, msg = "ok", data = res })); } catch (Exception ex) { LogService.Instance.AddAsync(Level.Error, ex); return(Json(new { code = 500, msg = "error" })); } }
public ActionResult List(int?page = 1) { CommentInfoListQuery listModel = new CommentInfoListQuery(); listModel.PageIndex = Convert.ToInt32(page); listModel.PageSize = 10; CommentInfoListModelResult result = _commentService.GetInfoPaged(listModel); if (result.List.Count == 0 && result.TotalCount != 0 && page != 1) { page--; return(RedirectToAction("list", new { page = page })); } var pageList = new StaticPagedList <CommentInfo>(result.List, listModel.PageIndex, listModel.PageSize, result.TotalCount); return(View(pageList)); }
public CommentInfoListModelResult GetInfoPaged(CommentInfoListQuery listModel) { CommentInfoListModelResult result = new CommentInfoListModelResult(); result.List = new List <CommentInfo>(); StringBuilder builder = new StringBuilder("select Comment.*,Article.Title as ArticleTitle from comment left join Article on Article.ArticleId = Comment.articleid where Comment.Enable = 1"); if (!string.IsNullOrEmpty(listModel.ArticleId)) { builder.Append(" and Comment.ArticleId = ?"); } if (string.IsNullOrEmpty(listModel.Order)) { builder.Append(" order by Comment.createtime desc,Comment.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(RowToModelInfo(item)); } StringBuilder countSql = new StringBuilder("select count(1) from Comment left join Article on Article.ArticleId = Comment.articleid where Comment.Enable = 1"); if (!string.IsNullOrEmpty(listModel.ArticleId)) { countSql.Append(" and Comment.ArticleId = ?"); } object countNum = SQLiteHelper.ExecuteScalar(countSql.ToString(), para); result.TotalCount = Convert.ToInt32(countNum); return(result); }