// PUT: api/Jams/5 public IHttpActionResult Put(int id, [FromBody] Jam jam) { try { if (jam == null) { return(BadRequest("Jam cannot be null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var jamRepository = new Models.JamRepository(); var updatedJam = jamRepository.Save(id, jam); if (updatedJam == null) { return(NotFound()); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Post([FromBody] Jam jam) { try { if (jam == null) { return(BadRequest("Jam cannot be null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var jamRepository = new Models.JamRepository(); var newJam = jamRepository.Save(jam); if (newJam == null) { return(Conflict()); } return(Created <Jam>(Request.RequestUri + newJam.JamId.ToString(), newJam)); } catch (Exception ex) { return(InternalServerError(ex)); } }