public IActionResult Post([FromBody] ObsSessionDtoForCreation newObsSessionDto) { ObsSession obsSession = _mapper.Map <ObsSession>(newObsSessionDto); // Lookup and verify the location id if (newObsSessionDto.LocationId != null) { Location locationEntity = _locationsRepository.GetLocation(newObsSessionDto.LocationId ?? 0); if (locationEntity == null) { return(BadRequest("Invalid LocationId")); } obsSession.Location = locationEntity; } ObsSession addedObsSession = _obsSessionsRepository.AddObsSession(obsSession); if (addedObsSession == null) { return(StatusCode(500, "Something went wrong creating an observation session")); } _mainDbContext.SaveChanges(); _reportTextManager.ParseAndStoreObservations(addedObsSession); _logger.LogInformation("Created an observation session:"); _logger.LogInformation(PocoPrinter.ToString(addedObsSession)); ObsSessionDto addedObsSessionDto = _mapper.Map <ObsSessionDto>(addedObsSession); return(CreatedAtRoute("GetOneObsSession", new { id = addedObsSessionDto.Id }, addedObsSessionDto)); }