public IHttpActionResult PutSandwhich(int id, Sandwhich sandwhich) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sandwhich.Id) { return(BadRequest()); } db.Entry(sandwhich).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SandwhichExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetSandwhich(int id) { Sandwhich sandwhich = db.Sandwhich.Find(id); if (sandwhich == null) { return(NotFound()); } return(Ok(sandwhich)); }
public IHttpActionResult PostSandwhich(Sandwhich sandwhich) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Sandwhich.Add(sandwhich); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = sandwhich.Id }, sandwhich)); }
public IHttpActionResult DeleteSandwhich(int id) { Sandwhich sandwhich = db.Sandwhich.Find(id); if (sandwhich == null) { return(NotFound()); } db.Sandwhich.Remove(sandwhich); db.SaveChanges(); return(Ok(sandwhich)); }