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); }