// PUT api/Announcement/5 public async Task<IHttpActionResult> PutAnnouncement(int id, Announcement announcement) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != announcement.Id) { return BadRequest(); } _db.Entry(announcement).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnouncementExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostAnnouncement(Announcement announcement) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _db.Announcements.Add(announcement); await _db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = announcement.Id }, announcement); }