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