// PUT odata/Event(5) public async Task<IHttpActionResult> Put([FromODataUri] int key, Event @event) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != @event.Id) { return BadRequest(); } db.Entry(@event).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventExists(key)) { return NotFound(); } else { throw; } } return Updated(@event); }
// POST odata/Event public async Task<IHttpActionResult> Post(Event @event) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Events.Add(@event); await db.SaveChangesAsync(); return Created(@event); }
private JsonEvent ToJsonEvent(Event e) { return new JsonEvent { Id = e.Id, Event = e.Text, Comments = e.Comments, Contact = e.Contact, Time = e.Time, SourceReliability = e.SourceReliability != null ? e.SourceReliability.Text : null, Topic = e.Topic, User = e.User != null ? e.User.Name : null }; }