Example #1
0
        public HttpResponseMessage GetShortItem()
        {
            ReturnHelper rh      = new ReturnHelper(200, null, 0, "");
            string       shortid = HttpContext.Current.Request["shortid"];

            try
            {
                if (string.IsNullOrEmpty(shortid))
                {
                    rh.msg  = "缺少微语id";
                    rh.code = 300;
                }
                else
                {
                    Shorts    obj      = new Shorts();
                    string    strWhere = string.Format(" Shortid='{0}' ", shortid);
                    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)));
        }
Example #2
0
        public HttpResponseMessage GetShortsPage()
        {
            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
                {
                    Shorts obj      = new Shorts();
                    string strWhere = " 1=1";
                    if (!string.IsNullOrEmpty(key))
                    {
                        strWhere += string.Format(" and (Short_Content 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 Shorts where {0}", strWhere), SqlHelper.CreateConn());
                        rh.data   = dt;
                        rh.msg    = "获取成功";
                    }
                }
            }
            catch (Exception e)
            {
                rh.code = 500;
                rh.msg  = "处理错误";
            }
            return(ReturnJson(JsonConvert.SerializeObject(rh)));
        }