public async Task <IHttpActionResult> PutParticipant(Guid id, ParticipantAdminDto participantDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != participantDto.participantId) { return(BadRequest()); } Participant participant = await db.Participants.FindAsync(participantDto.participantId); if (participant == null) { return(BadRequest()); } participant.FirstName = participantDto.firstName; participant.LastName = participantDto.lastName; participant.Dob = participantDto.dob; participant.Gender = participantDto.gender; db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetParticipant(Guid id) { ParticipantAdminDto participant = await db.Participants.Select(AsParticipantAdminDto) .Where(p => p.participantId == id) .FirstOrDefaultAsync(); if (participant == null) { return(NotFound()); } return(Ok(participant)); }
public async Task <IHttpActionResult> PostParticipant(ParticipantAdminDto participantDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Participant participant = ToParticipant(participantDto); participant.ParticipantId = Guid.NewGuid(); participant.ActivationCode = HV.Connections.CreateParticipantIdentityCode( participant.FirstName + ' ' + participant.LastName, participant.SecretQuestion, participant.SecretAnswer, participant.ParticipantId.ToString() ); participant.EnrollmentDate = DateTime.Now; db.Participants.Add(participant); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ParticipantExists(participant.ParticipantId)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("GetParticipantAdminDto", new { id = participant.ParticipantId }, ToParticipantAdminDto(participant))); }