public IHttpActionResult PutFragrance(int id, Fragrance fragrance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != fragrance.id) { return(BadRequest()); } db.Entry(fragrance).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FragranceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetFragrance(int id) { Fragrance fragrance = db.Fragrances.Find(id); if (fragrance == null) { return(NotFound()); } return(Ok(fragrance)); }
public IHttpActionResult PostFragrance(Fragrance fragrance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Fragrances.Add(fragrance); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = fragrance.id }, fragrance)); }
public IHttpActionResult DeleteFragrance(int id) { Fragrance fragrance = db.Fragrances.Find(id); if (fragrance == null) { return(NotFound()); } db.Fragrances.Remove(fragrance); db.SaveChanges(); return(Ok(fragrance)); }