コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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;
        }