public IActionResult Create([FromBody] NationalParkDTO nationalParkDTO) { if (nationalParkDTO == null) { return(BadRequest()); } if (_nationalParkRepository.ExsistsByName(nationalParkDTO.Name)) { ModelState.AddModelError("", "National Park exsists"); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest()); } var nationalPark = _mapper.Map <NationalPark>(nationalParkDTO); if (!_nationalParkRepository.Create(nationalPark)) { ModelState.AddModelError("", $"Something went wrong when saving the record {nationalPark.Name} "); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("GetNationalPark", new { nationalParkId = nationalPark.Id }, nationalPark)); }
public ActionResult <NationalPark> Create(NationalPark nationalPark) { _nationalParkRepository.Create(nationalPark); return(CreatedAtRoute("GetNationalPark", new { id = nationalPark.Id.ToString() }, nationalPark)); }