Example #1
0
        public HttpResponseBase SaveRedirect()
        {
            string json = string.Empty;
            try
            {
                Redirect redirect = new Redirect();
                _redirectMgr = new RedirectMgr(mySqlConnectionString);
                _serialMgr = new SerialMgr(mySqlConnectionString);
                redirect.redirect_name = Request.Params["redirect_name"].ToString();
                if (!string.IsNullOrEmpty(Request.Params["group_id"]))
                {
                    redirect.group_id = uint.Parse(Request.Params["group_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["user_group_id"]))
                {
                    redirect.user_group_id = int.Parse(Request.Params["user_group_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["redirect_status"]))
                {
                    redirect.redirect_status = uint.Parse(Request.Params["redirect_status"]);
                }
                redirect.redirect_url = Request.Params["redirect_url"];
                redirect.redirect_note = Request.Params["redirect_note"];

                redirect.redirect_ipfrom = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault().ToString();
                if (!string.IsNullOrEmpty(Request.Params["redirect_id"]))
                {
                    redirect.redirect_id = uint.Parse(Request.Params["redirect_id"]);
                    redirect.redirect_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime());
                    if (_redirectMgr.Update(redirect) > 0)
                    {
                        json = "{success:true}";
                    }
                }
                else
                {
                    redirect.redirect_id = uint.Parse((_serialMgr.GetSerialById(4).Serial_Value + 1).ToString());
                    redirect.redirect_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime());
                    redirect.redirect_updatedate = redirect.redirect_createdate;
                    if (_redirectMgr.Save(redirect) > 0)
                    {
                        Serial serial = new Serial();
                        serial.Serial_id = 4;
                        serial.Serial_Value = redirect.redirect_id;
                        _serialMgr.Update(serial);
                        json = "{success:true}";
                    }
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }