public HttpResponseMessage AddScomment(Scomments obj) { ReturnHelper rh = new ReturnHelper(200, null, 0, ""); try { obj.Scomment_Id = Guid.NewGuid().ToString("N"); obj.Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); int i = obj.Insert(); if (i > 0) { rh.msg = "添加评论成功"; rh.totals = i; } else { rh.msg = "添加评论失败"; rh.code = 400; } } catch (Exception e) { rh.code = 500; rh.msg = "服务器错误,请通知管理员"; } return(ReturnJson(JsonConvert.SerializeObject(rh))); }
public HttpResponseMessage GetScommentsPage() { 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 { Scomments obj = new Scomments(); string strWhere = " 1=1"; int begin = (Convert.ToInt32(page) - 1) * Convert.ToInt32(limit); int end = Convert.ToInt32(page) * Convert.ToInt32(limit); DataTable dt = obj.GetPage("*", "Time desc", strWhere, begin, end); if (dt.Rows.Count > 0) { rh.totals = SqlHelper.Count(string.Format("select count(*) from Scomments where {0}", strWhere), SqlHelper.CreateConn()); rh.data = dt; rh.msg = "获取成功"; } } } catch (Exception e) { rh.code = 500; rh.msg = "处理错误"; } return(ReturnJson(JsonConvert.SerializeObject(rh))); }