예제 #1
0
        public HttpResponseMessage UpdateShort(Shorts 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(" Shortid=@Shortid", obj.Shortid);
                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 LikeShort(Shorts obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

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