public IHttpActionResult PostMessage(Message message) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _context.Messages.Add(message); _context.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = message.Id }, message); }
public IHttpActionResult PutMessage(int id, Message message) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != message.Id) { return BadRequest(); } _context.Entry(message).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MessageExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }