Exemple #1
0
        public void SaveRunner(PuzzleRunner r)
        {
            var conn = GetConnection();

            try
            {
                string     deleteSql = @"DELETE FROM PuzzleRunners WHERE name=@name";
                SqlCommand deleteCmd = new SqlCommand(deleteSql, conn);
                deleteCmd.Parameters.Add("@name", SqlDbType.NVarChar);
                deleteCmd.Parameters["@name"].Value = r.name;
                deleteCmd.ExecuteNonQuery();

                string     insertSql = @"INSERT INTO PuzzleRunners (name, color, latitude, longitude) values (@name, @color, @latitude, @longitude)";
                SqlCommand insertCmd = new SqlCommand(insertSql, conn);
                insertCmd.Parameters.Add("@name", SqlDbType.NVarChar);
                insertCmd.Parameters.Add("@color", SqlDbType.NVarChar);
                insertCmd.Parameters.Add("@latitude", SqlDbType.Float);
                insertCmd.Parameters.Add("@longitude", SqlDbType.Float);

                insertCmd.Parameters["@name"].Value      = r.name;
                insertCmd.Parameters["@color"].Value     = r.color;
                insertCmd.Parameters["@latitude"].Value  = r.latitude;
                insertCmd.Parameters["@longitude"].Value = r.longitude;

                insertCmd.ExecuteNonQuery();
            }
            finally
            {
                ReleaseConnection(conn);
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PuzzleRunner result = new PuzzleRunner()
            {
                name      = Request.Params["name"],
                color     = Request.Params["color"],
                latitude  = double.Parse(Request.Params["latitude"]),
                longitude = double.Parse(Request.Params["longitude"]),
            };

            SaveRunner(result);

            Response.Write(JsonConvert.SerializeObject(result));
        }