public HttpResponseMessage Create(OrganizerCreateModel model) { if (model == null) { ModelState.AddModelError("", "You did not send any data!"); } if (!ModelState.IsValid) { return(Request.CreateErrorResponse( HttpStatusCode.BadRequest, ModelState )); } IOrganizerService organizerService = new OrganizerService(); int id = organizerService.Create(model); return(Request.CreateResponse(HttpStatusCode.Created, id)); }
public int Create(OrganizerCreateModel model) { using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "SongNames_CreateUpdateDelete"; cmd.Parameters.AddWithValue("@SongName", model.SongName); cmd.Parameters.AddWithValue("@Lyrics", model.Lyrics); cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); return((int)cmd.Parameters["@id"].Value); } }