插入:
[HttpPost]
public void InsertDirector(Director director)
{
myConnection.Open();
var query = "INSERT INTO dbo.AWD_Directors (AwardTitleId, PersonId, NameId, DirectorSequence, IsOnBallot, Concatenation, WhoEntered, WhoChanged) VALUES (" + director.AwardTitleId + ", " + director.PersonId + ", " + director.NameId + ", " + director.DirectorSequence + ", " + director.IsOnBallot + ", '" + director.Concatenation + "', 0, 0)";
var cmd = new SqlCommand(query, myConnection);
cmd.ExecuteNonQuery();
myConnection.Close();
}
更新:
[HttpPost]
public void UpdateDirector(Director director)
{
myConnection.Open();
var query = "UPDATE dbo.AWD_Directors SET NameId=" + director.NameId + ", DirectorSequence = " + director.DirectorSequence + ", IsOnBallot = " + director.IsOnBallot + ", Concatenation = '" + director.Concatenation + "' WHERE AwardTitleId = " + director.AwardTitleId + "AND PersonId = " + director.PersonId + " AND NameId = " + director.NameId;
var cmd = new SqlCommand(query, myConnection);
cmd.ExecuteNonQuery();
myConnection.Close();
}
插入路线:
routes.MapHttpRoute(name: "InsertDirector", routeTemplate: "api/awards/directors", defaults: new
{
controller = "Awards", action = "InsertDirector"
});
更新路线:
routes.MapHttpRoute(name: "UpdateDirector", routeTemplate: "api/awards/directors", defaults: new
{
controller = "Awards",
action = "UpdateDirector"
});
我可以使用哪些命名约定来改进我所拥有的内容?
顺便说一句,不要介意内联 SQL。这将在以后更改。