public IHttpActionResult PostStudentDB(StudentDB studentDB) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.StudentDB.Add(studentDB); try { db.SaveChanges(); } catch (DbUpdateException) { if (StudentDBExists(studentDB.Student_ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = studentDB.Student_ID }, studentDB)); }
public IHttpActionResult PutStudentDB(int id, StudentDB studentDB) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != studentDB.Student_ID) { return(BadRequest()); } db.Entry(studentDB).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentDBExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetStudentDB(int id) { StudentDB studentDB = db.StudentDB.Find(id); if (studentDB == null) { return(NotFound()); } return(Ok(studentDB)); }
public IHttpActionResult DeleteStudentDB(int id) { StudentDB studentDB = db.StudentDB.Find(id); if (studentDB == null) { return(NotFound()); } db.StudentDB.Remove(studentDB); db.SaveChanges(); return(Ok(studentDB)); }