public IHttpActionResult PostOffenders(Offenders offenders) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Offenders.Add(offenders); try { db.SaveChanges(); } catch (DbUpdateException) { if (OffendersExists(offenders.OffendersId)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = offenders.OffendersId }, offenders)); }
public IHttpActionResult PutOffenders(int id, Offenders offenders) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != offenders.OffendersId) { return(BadRequest()); } db.Entry(offenders).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OffendersExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetOffenders(int id) { Offenders offenders = db.Offenders.Find(id); if (offenders == null) { return(NotFound()); } return(Ok(offenders)); }
public IHttpActionResult DeleteOffenders(int id) { Offenders offenders = db.Offenders.Find(id); if (offenders == null) { return(NotFound()); } db.Offenders.Remove(offenders); db.SaveChanges(); return(Ok(offenders)); }