public ArticleListModelResult GetPaged(ArticleListQuery listModel) { ArticleListModelResult result = new ArticleListModelResult(); result.List = new List <Article>(); StringBuilder builder = new StringBuilder("select * from article where Enable = 1"); List <object> paraList = new List <object>(); if (listModel.PublishStatus != PublishStatus.All) { builder.Append(" and PublishStatus = ?"); paraList.Add((int)listModel.PublishStatus); } if (!string.IsNullOrEmpty(listModel.TheUserData)) { builder.Append(" and createUser = ? "); paraList.Add(listModel.TheUserData); } if (string.IsNullOrEmpty(listModel.Order)) { builder.Append(" order by createdtime desc,articleId asc"); } else { builder.Append(listModel.Order); } DataTable dt = SQLiteHelper.ExecutePager(listModel.PageIndex, listModel.PageSize, builder.ToString(), paraList.ToArray()); foreach (DataRow item in dt.Rows) { result.List.Add(RowToModel(item)); } StringBuilder countSqlBuilder = new StringBuilder("select count(1) from article where Enable = 1"); if (listModel.PublishStatus != PublishStatus.All) { countSqlBuilder.Append(" and PublishStatus = ?"); } if (!string.IsNullOrEmpty(listModel.TheUserData)) { countSqlBuilder.Append(" and createUser = ? "); } object countNum = SQLiteHelper.ExecuteScalar(countSqlBuilder.ToString(), paraList.ToArray()); result.TotalCount = Convert.ToInt32(countNum); return(result); }
public ActionResult Index(int?page = 1) { ArticleListQuery listModel = new ArticleListQuery(); listModel.PageIndex = Convert.ToInt32(page); listModel.PageSize = 10; ArticleListModelResult result = _articleService.GetPaged(listModel); var pageList = new StaticPagedList <Article>(result.List, listModel.PageIndex, listModel.PageSize, result.TotalCount); return(View(pageList)); }
public ActionResult Index(int?page = 1) { ArticleListQuery query = new ArticleListQuery(); query.PageIndex = Convert.ToInt32(page); query.PageSize = 10; query.PublishStatus = PublishStatus.All; if (_permissionService.OnlyAccessSelf(ContextUser.Email, Permission.HuiChengSiteList)) { query.TheUserData = ContextUser.Email; } ArticleListModelResult result = _articleService.GetPaged(query); var pageList = new StaticPagedList <Article>(result.List, query.PageIndex, query.PageSize, result.TotalCount); return(View(pageList)); }