public IHttpActionResult PostUserApp(UserApp userapp) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.UserApps.Add(userapp); try { db.SaveChanges(); } catch (DbUpdateException) { if (UserAppExists(userapp.UserID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = userapp.UserID }, userapp); }
// PUT api/UserApp/5 public IHttpActionResult PutUserApp(int id, UserApp userapp) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != userapp.UserID) { return BadRequest(); } db.Entry(userapp).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserAppExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }