trying to understand the POST and how it works. I am trying to update a table using a store procedure and the POST gets ignored and it fires the GET. Below are my classes can someone put me in the write direction if this can be done this way.
interface:
[HttpPost]
HttpResponseMessage POST(string name1, string number, string myid, string vnumber)
controller:
[HttpPost]
public HttpResponseMessage POST(string name1, string number, string myid, string vnumber)
{
repository.POST(name1, number, myid, vnumber);
return new HttpResponseMessage();
}
repository:
[HttpPost]
public HttpResponseMessage POST(string name1, string number, string myid, string vnumber)
{
MySqlCommand cmd = new MySqlCommand();
try
{
using (_conn)
{
cmd.Connection = _conn;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "spWebApiTest";
cmd.Parameters.Add(new MySqlParameter("name", name1));
cmd.Parameters.Add(new MySqlParameter("number", number));
cmd.Parameters.Add(new MySqlParameter("myid", myid));
cmd.Parameters.Add(new MySqlParameter("vnumber", vnumber));
_conn.Open();
cmd.ExecuteNonQuery();
// return contracts.ToArray();
return new HttpResponseMessage();
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (cmd.Connection.State != ConnectionState.Closed)
{
cmd.Connection.Close();
cmd = null;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire