private async Task <DtoRegistration> createRegistration() { var owner = await GetPersonRepository().AddAsync("ben", null); var eventEntity = new Event(0, "Title", "Marathon1", new DateTime(2021, 6, 21)); var newEvent = await GetEventRepository().AddAsync(eventEntity); var team = new Team { OwnerID = owner.ID, EventID = newEvent.ID, Name = $"New Team {owner.ID}-{newEvent.ID}" }; team = await GetTeamRepository().AddAsync(team); var uncreatedDtoRegistration = new DtoRegistration { OwnerID = owner.ID, TeamID = team.ID }; var dtoRegistrationResponse = await GetRegistrationController().Add(uncreatedDtoRegistration); return(dtoRegistrationResponse.Value); }
public static Registration DtoToDataAccess(DtoRegistration d) { return(new Registration { status = d.Status }); }
public async Task <ActionResult <DtoRegistration> > Edit([FromBody] DtoRegistration dtoRegistration) { log.LogInformation("Editing dtoRegistration {dtoRegstration}", dtoRegistration); if (!ModelState.IsValid) { return(BadRequest(getModelStateErrorMessage())); } if (!await registrationRepository.ExistsAsync(dtoRegistration.ID)) { return(NotFound("Registration id does not exist")); } var registrationToEdit = mapper.Map <Registration>(dtoRegistration); var editedRegistration = await registrationRepository.EditAsync(registrationToEdit); return(mapper.Map <DtoRegistration>(editedRegistration)); }
public async Task <ActionResult <DtoRegistration> > Add([FromBody] DtoRegistration dtoRegistration) { log.LogInformation("Adding new dtoRegistration {dtoRegistration}", dtoRegistration); if (!ModelState.IsValid) { return(BadRequest(getModelStateErrorMessage())); } if (dtoRegistration.ID != 0) { return(BadRequest("Cannot add with a valid id")); } var registrationToAdd = mapper.Map <Registration>(dtoRegistration); var updatedRegistration = await registrationRepository.AddAsync(registrationToAdd); return(mapper.Map <DtoRegistration>(updatedRegistration)); }