public IHttpActionResult PutUser(int id, MvcModel user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.Id) { return(BadRequest()); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostUser(MvcModel user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Users.Add(user); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = user.Id }, user)); }