public IActionResult CreateNationalPark([FromBody] NationalParkDto nationalParkDto) { if (nationalParkDto == null) { return(BadRequest()); } if (_nationalParkRepository.NationalParkExsists(nationalParkDto.name)) { ModelState.AddModelError("", "National park exists."); return(StatusCode(404, ModelState)); } var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDto); if (!_nationalParkRepository.CreateNationalPark(nationalParkObj)) { ModelState.AddModelError("", $"Problem while saving the record {nationalParkDto.name}"); } return(CreatedAtRoute("GetNationalPark", new { nationalParkId = nationalParkObj.id }, nationalParkObj)); }