public IActionResult PostNationalPark([FromBody] NationalParkDto nationalParkDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_nationalParkRepository.NationalParkExists(nationalParkDto.Name)) { ModelState.AddModelError("duplicates", "Park already exists in the database"); return(BadRequest(ModelState)); } var nationalParkToPost = _mapper.Map <NationalPark>(nationalParkDto); if (!_nationalParkRepository.AddNationalParkToDatabase(nationalParkToPost)) { ModelState.AddModelError(string.Empty, "Something went wrong while saving the park"); return(StatusCode(StatusCodes.Status500InternalServerError, ModelState)); } nationalParkDto.Id = nationalParkToPost.Id; return(CreatedAtAction("GetNationalParkById", new { nationalParkId = nationalParkToPost.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() }, nationalParkDto)); }