Ejemplo n.º 1
0
        public IActionResult CreateNationPark([FromBody] NationalParkDto nationalParkDto)
        {
            if (nationalParkDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (_nationalParkRepository.NationalParkExists(nationalParkDto.Name))
            {
                ModelState.AddModelError("", "National Park Exists!");
                return(StatusCode(404, ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var nationalParkObj = _mapper.Map <NationalPark>(nationalParkDto);

            if (!_nationalParkRepository.CreateNationNalPark(nationalParkObj))
            {
                ModelState.AddModelError("", $"Something went wrong when savind the record {nationalParkObj.Name}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetNationalPark", new { Version = HttpContext.GetRequestedApiVersion().ToString(), nationalParkId = nationalParkObj.Id }, nationalParkObj));
        }