public IActionResult Index(int? page, string keywords = null) { if (page == null || page < 1) { page = 1; } var request = new QueryArticleRequest { PageIndex = page.Value, PageSize = 20, Status = Core.Enums.ArticleStatus.Publish, Keywords = keywords }; int total; var articleList = this.ArticleService.Query(request, out total); var vm = new ViewModels.Article.ArticleListViewModel { ArticleList = articleList, PageIndex = request.PageIndex, PageSize = request.PageSize, Total = total }; ViewBag.Keywords = keywords; return this.View("~/Views/Article/ArticleList.cshtml", vm); }
public IActionResult Query(QueryArticleRequest request) { int total; var list = this.ArticleService.Query(request, out total); var result = PagedOperationResult<ArticleModel>.SuccessResult(list, total); return this.ApiResponse(result); }
public List<ArticleModel> Query(QueryArticleRequest model, out int total) { StringBuilder sb = new StringBuilder("WHERE Status!=0"); DynamicParameters para = new DynamicParameters(); if (model.Status.HasValue) { sb.Append(" AND Status=@Status"); para.Add("@Status", (byte)model.Status.Value); } if (model.Keywords != null) { sb.Append(" AND Title LIKE @Keywords"); para.Add("@Keywords", "%" + model.Keywords + "%"); } var list = this.QueryByCondition(model.PageIndex, model.PageSize, out total, sb.ToString(), null, para); return list; }