public IActionResult UpDateNationalPark(int nationalParkId, [FromBody] NationalParkDtos nationalParkDto) { if (nationalParkDto == null || nationalParkId != nationalParkDto.Id) { return(BadRequest(ModelState)); } //if (_nationalParkService.NationalParkExists(nationalParkDto.Name)) //{ // ModelState.AddModelError("", "National Park Exists ! "); // return StatusCode(404, ModelState); //} var nationalParakObj = _mapper.Map <NationalPark>(nationalParkDto); if (!_nationalParkService.UpdateNationalPark(nationalParakObj)) { ModelState.AddModelError("", $"Something Went Wrong When Updating the Record {nationalParakObj.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult CreateNationalPark([FromBody] NationalParkDtos nationalParkDtos) { if (nationalParkDtos == null) { return(BadRequest(ModelState)); } if (_nationalParkService.NationalParkExists(nationalParkDtos.Name)) { ModelState.AddModelError("", "National Park Exists ! "); return(StatusCode(404, ModelState)); } //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} var nationalParakObj = _mapper.Map <NationalPark>(nationalParkDtos); if (!_nationalParkService.CreateNationalPark(nationalParakObj)) { ModelState.AddModelError("", $"Something Went Wrong When Saving the Record {nationalParakObj.Name}"); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("GetNationalPark", new { NationalParkId = nationalParakObj.Id }, nationalParakObj)); }