public async Task <IActionResult> CreateParticipant([FromBody] ParticipantCreateDto participant) { if (participant == null) { return(BadRequest("ParticipantDto object is null.")); } else { var participantEntity = _mapper.Map <Participant>(participant); _repository.Participant.CreateParticipant(participantEntity); await _repository.SaveAsync(); var participantToReturn = _mapper.Map <ParticipantDto>(participantEntity); return(CreatedAtRoute("GetParticipant", new { id = participantToReturn.Id }, participantToReturn)); } }
public void ThereIsAParticipant(string participantName) { var createParticipant = new ParticipantCreateDto { Name = participantName, Phone = "0 123 456797", Email = "*****@*****.**", Address = new AddressDto { Street = "Augsburger Straße", HouseNumber = "56", PostCode = 86381, City = "Krumbach", Country = Country.Germany }, Birthday = new DateTime(1983, 5, 15) }; Task.WaitAll(testContext.PostAsync(testContext.ParticipantsEndPoint, createParticipant)); }
public async Task <ActionResult> Add(ParticipantCreateDto dto) { var participant = new Participant { Name = dto.Name, Address = new Address { City = dto.Address.City, Country = dto.Address.Country, HouseNumber = dto.Address.HouseNumber, PostCode = dto.Address.PostCode, Street = dto.Address.Street }, Birthday = dto.Birthday, Email = dto.Email, Phone = dto.Phone }; var addedParticipant = await db.Participants.AddAsync(participant); await db.SaveChangesAsync(); return(CreatedAtAction(nameof(GetById), addedParticipant.Entity.Id)); }