インサート:
[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 は気にしないでください。これは後で変更されます。