Example #1
0
        public HttpResponseMessage AddVisitRecord(Visits obj)
        {
            ReturnHelper rh = new ReturnHelper(200, null, 0, "");

            try
            {
                obj.Visitid   = Guid.NewGuid().ToString("N");
                obj.Visittime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                obj.Ip        = IPHelper.GetHostIP();
                obj.Address   = IPHelper.GetHostAddress(obj.Ip);
                string selectsql = string.Format(" select Times from Visits where IP='{0}'", obj.Ip);
                string times     = SqlHelper.ShowData(selectsql, "Times", SqlHelper.CreateConn());
                if (!string.IsNullOrEmpty(times))
                {
                    obj.Times = Convert.ToInt32(times) + 1;//访问次数+1
                }
                else
                {
                    obj.Times = 1; //第一次访问
                }
                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)));
        }