public JsonResult GetList(PeijianSearchModel searchModel) { try { using (var context = ZhangweiContextFactory.Create()) { var query = context.Peijian.AsQueryable(); List <PeijianDataModel> peijianList = null; if (!string.IsNullOrEmpty(searchModel.Keyword)) { query = query .Where(p => p.Name.IndexOf(searchModel.Keyword) > -1); } peijianList = query .OrderByDescending(p => p.Id) .ToList(); return(Json(new { success = true, peijianList = peijianList.Skip(searchModel.Start).Take(searchModel.PageSize), totalCount = peijianList.Count })); } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } }
public JsonResult GetAutoCompleteList(PeijianSearchModel searchModel) { try { using (var context = ZhangweiContextFactory.Create()) { List <PeijianDataModel> peijianList = null; if (string.IsNullOrEmpty(searchModel.Keyword)) { peijianList = context.Peijian.ToList(); } else { peijianList = context.Peijian.Where(p => p.Name.IndexOf(searchModel.Keyword) > -1 || p.Tag.IndexOf(searchModel.Keyword) > -1).Take(30).ToList(); } return(Json(new { success = true, peijianList = peijianList })); } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } }