예제 #1
0
        public HttpResponseMessage UpdateEssay(Essays obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

            try
            {
                obj.Update_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                obj.Ip          = IPHelper.GetHostIP();
                obj.Address     = IPHelper.GetHostAddress(obj.Ip);
                int i = obj.Update(" Essayid=@Essayid", obj.Essayid);
                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)));
        }
예제 #2
0
        public HttpResponseMessage ViewEssay(Essays obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

            try
            {
                string selectsql = string.Format(" select Views from Essays where Essayid='{0}'", obj.Essayid);
                string times     = SqlHelper.ShowData(selectsql, "Views", SqlHelper.CreateConn());
                if (!string.IsNullOrEmpty(times))
                {
                    obj.Views = Convert.ToInt32(times) + 1;//访问次数+1
                }
                else
                {
                    obj.Views = 1;//第一次访问
                }
                int i = obj.Update(" Essayid=@Essayid", obj.Essayid);
                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)));
        }