public IHttpActionResult Get(int id) { try { Student res = StudentsDB.GetStudentById(id); if (res == null) { return(Content(HttpStatusCode.NotFound, $"student with id= {id} was not found!")); } return(Ok(res)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Delete(int id) { try { Student s = StudentsDB.GetStudentById(id); if (s != null) { int res = StudentsDB.DeleteStudentById(id); if (res == 1) { return(Ok()); } return(Content(HttpStatusCode.BadRequest, $"student with id {id} exsits but could not be deleted!!!")); } return(Content(HttpStatusCode.NotFound, "student with id = " + id + " was not found to delete!!!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Put(Student student2Update) { try { Student s = StudentsDB.GetStudentById(student2Update.ID); if (s != null) { int res = StudentsDB.UpdateStudent(student2Update); if (res == 1) { return(Ok()); } return(Content(HttpStatusCode.NotModified, $"student with id {student2Update.ID} exsits but could not be modified!!!")); } return(Content(HttpStatusCode.NotFound, "student with id = " + student2Update.ID + " was not found to update!!!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }