//[Authorize] public HttpResponseMessage GetStudentsPagination([FromBody] StudentPagedModel model) { /* 请求示例: * { "PageSize":10, "PageIndex":0, "Name":"赵%"} */ var result = _testService.GetStudentsPagination(model); var data = new JsonResultBuilder() .SetCode(JsonResultCode.OK) .SetMessage("success") .SetResult(result.Data, result.Count).Build(); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(data.ToString()) }); }
/// <summary> /// 分页查询 /// </summary> /// <param name="model"></param> /// <returns></returns> public PagedDto GetStudentsPagination(StudentPagedModel model) { var predicateGroup = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List <IPredicate>() }; if (!string.IsNullOrEmpty(model.Sex)) { var predicate1 = Predicates.Field <Student>(n => n.Ssex, Operator.Eq, model.Sex); predicateGroup.Predicates.Add(predicate1); } if (!string.IsNullOrEmpty(model.Name)) { var predicate2 = Predicates.Field <Student>(n => n.Sname, Operator.Like, model.Name); predicateGroup.Predicates.Add(predicate2); } IList <ISort> sort = new List <ISort> { new Sort() { PropertyName = "sid", Ascending = true }, new Sort() { PropertyName = "sage", Ascending = false } }; long totalCount = 0L; var students = DataRepository.GetPage <Student>(model.PageIndex, model.PageSize, out totalCount, predicateGroup, sort); var dataList = AutoMapperHelper <IEnumerable <Student>, IEnumerable <StudentDto> > .AutoConvert(students); return(new PagedDto() { Count = totalCount, Data = dataList }); }