public async Task <IActionResult> PutMessage([FromRoute] int id, [FromBody] Message message) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != message.MessageId) { return(BadRequest()); } _context.Entry(message).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MessageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser([FromRoute] int id, [FromBody] User user) { try { if (id == user.UserId) { _context.Entry(user).State = EntityState.Modified; } else { return(BadRequest(ModelState)); } // (CheckEmailAvailability(user.Email)) await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(Ok(new { data = user, message = "User updated successfully" })); }