public IHttpActionResult PutCliente(int id, Cliente cliente) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cliente.ClienteId) { return(BadRequest()); } db.Entry(cliente).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClienteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.UserId) { return(BadRequest()); } if (user.Password == null) { User _user = db.Users.Find(id); user.Password = _user.Password; } var local = db.Set <User>() .Local .FirstOrDefault(f => f.UserId == id); if (local != null) { db.Entry(local).State = EntityState.Detached; } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }