public async Task<IHttpActionResult> PostParticipant(Participant participant) { if (!ModelState.IsValid) { return BadRequest(ModelState); } participant.ParticipantID = Guid.NewGuid(); Guid valid_id = Guid.NewGuid(); participant.ValidationID = valid_id; participant.Activated = false; participant.DateCreated = DateTime.Today; db.Participants.Add(participant); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ParticipantExists(participant.ParticipantID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = participant.ParticipantID }, participant); }
public async Task<IHttpActionResult> PutParticipant(Guid id, Participant participant) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != participant.ParticipantID) { return BadRequest(); } db.Entry(participant).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParticipantExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }