public HttpResponseMessage GetEssayItem() { ReturnHelper rh = new ReturnHelper(200, null, 0, ""); string essayid = HttpContext.Current.Request["essayid"]; try { if (string.IsNullOrEmpty(essayid)) { rh.msg = "缺少文章id"; rh.code = 300; } else { Essays obj = new Essays(); string strWhere = string.Format(" Essayid='{0}'", essayid); DataTable dt = obj.GetPage("*", "Report_Time desc", strWhere, 0, 1); if (dt.Rows.Count > 0) { rh.totals = 1; rh.data = dt; rh.msg = "获取成功"; } } } catch (Exception e) { rh.code = 500; rh.msg = "处理错误"; } return(ReturnJson(JsonConvert.SerializeObject(rh))); }
public HttpResponseMessage GetEssaysPage() { ReturnHelper rh = new ReturnHelper(200, null, 0, ""); string key = HttpContext.Current.Request["key"]; string limit = HttpContext.Current.Request["limit"]; string page = HttpContext.Current.Request["page"]; try { if (string.IsNullOrEmpty(limit) || string.IsNullOrEmpty(page)) { rh.msg = "缺少分页参数"; rh.code = 300; } else { Essays obj = new Essays(); string strWhere = " 1=1"; if (!string.IsNullOrEmpty(key)) { strWhere += string.Format(" and (Essay_Type like '%{0}%' or Essay_Title like '%{0}%' or Essay_Label like '%{0}%')", key); } int begin = (Convert.ToInt32(page) - 1) * Convert.ToInt32(limit); int end = Convert.ToInt32(page) * Convert.ToInt32(limit); DataTable dt = obj.GetPage("*", "Report_Time desc", strWhere, begin, end); if (dt.Rows.Count > 0) { rh.totals = SqlHelper.Count(string.Format("select count(*) from Essays where {0}", strWhere), SqlHelper.CreateConn()); rh.data = dt; rh.msg = "获取成功"; } } } catch (Exception e) { rh.code = 500; rh.msg = "处理错误"; } return(ReturnJson(JsonConvert.SerializeObject(rh))); }