public HttpResponseMessage Create(Game_Create game) { if (game == null) { ModelState.AddModelError("", "Your request contained no data."); } if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int Id = gamesService.Create(game); return(Request.CreateResponse(HttpStatusCode.Created, Id)); }
public int Create(Game_Create game) { using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); var cmd = CreateCommand(con, "Games_Create"); cmd.Parameters.AddWithValue("@Title", game.Title); cmd.Parameters.AddWithValue("@Publisher", game.Publisher); cmd.Parameters.AddWithValue("@Year", game.Year); cmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); return((int)cmd.Parameters["@Id"].Value); } }