public IHttpActionResult Puthobby(int id, hobby hobby) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hobby.id) { return(BadRequest()); } db.Entry(hobby).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!hobbyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void DBConnectedHobby() { MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=;database=semester_planner;"); con.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "select * from hobby"; cmd.Connection = con; MySqlDataReader reader = cmd.ExecuteReader(); Hobby = new List <hobby>(); while (reader.Read()) { int a = reader.GetInt32(0); String b = reader.GetValue(1) + ""; String c = reader.GetValue(2) + ""; String d = reader.GetValue(3) + ""; String e = reader.GetValue(4) + ""; hobby temp = new hobby(a, b, c, d, e); Hobby.Add(temp); } con.Close(); }
public void registrarHobby(hobby hobbyEntity) { using (var db = new MySqlEntities()) { db.hobbies.AddObject(hobbyEntity); db.SaveChanges(); } }
public IHttpActionResult Gethobby(int id) { hobby hobby = db.hobbies.Find(id); if (hobby == null) { return(NotFound()); } return(Ok(hobby)); }
public IHttpActionResult Posthobby(hobby hobby) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.hobbies.Add(hobby); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = hobby.id }, hobby)); }
public IHttpActionResult Deletehobby(int id) { hobby hobby = db.hobbies.Find(id); if (hobby == null) { return(NotFound()); } db.hobbies.Remove(hobby); db.SaveChanges(); return(Ok(hobby)); }