Beispiel #1
0
        public static string Start(RequestType request, out bool HasResponse)
        {
            string result = "";

            try
            {
                switch (request.FuncName)
                {
                case "Register":
                    Register_Params Rpar =
                        (Register_Params)JsonConvert.DeserializeObject(request.Params.ToString(), typeof(Register_Params));
                    result = Register(Rpar);
                    break;

                case "UpdateUserInformation":
                    UpdateUserInformation_Params UUIpar =
                        (UpdateUserInformation_Params)JsonConvert.DeserializeObject(request.Params.ToString(),
                                                                                    typeof(UpdateUserInformation_Params));
                    result = UpdateUserInformation(UUIpar);
                    break;

                default:
                    break;
                }
            }
            catch
            {
                result = "error in parameter format";
            }

            HasResponse = true;
            return(result);
        }
Beispiel #2
0
        private static string Register(Register_Params rp)
        {
            string       result = "";
            ResponseType rt     = new ResponseType();
            //DataContext db = new DataContext(Properties.Settings.Default.__connection);
            SqlConnection cnn = new SqlConnection(Properties.Settings.Default.__connection);
            SqlCommand    cmm = new SqlCommand();

            cmm.Connection = cnn;
            try
            {
                cmm.CommandText = "INSERT INTO UserIdentifier (Latitude,Longitude) output inserted.id" +
                                  " Values (" +
                                  "@Latitude,@Longitude)";
                cmm.Parameters.AddWithValue("Latitude", rp.Latitude);
                cmm.Parameters.AddWithValue("Longitude", rp.Longitude);



                try
                {
                    if (cnn.State != ConnectionState.Open)
                    {
                        cnn.Open();
                    }
                }
                catch { }
                object insertedId = cmm.ExecuteScalar();
                try
                {
                    if (cnn.State != ConnectionState.Closed)
                    {
                        cnn.Close();
                    }
                }
                catch { }
                rt.state  = true;
                rt.retVal = insertedId.ToString();
            }
            catch (Exception e)
            {
                rt.state  = false;
                rt.retVal = e.Message;
            }
            try
            {
                result = JsonConvert.SerializeObject(rt, typeof(ResponseType), new JsonSerializerSettings());
            }
            catch (Exception e)
            {
                result = "error : " + e.Message;
            }
            return(result);
        }