Пример #1
0
        public IActionResult CreateNationalPark([FromBody] NationalParkDTO nationalParkDTO)
        {
            if (nationalParkDTO == null)
            {
                return(BadRequest(ModelState));
            }

            if (_npRepo.NationalParkExist(nationalParkDTO.Name))
            {
                ModelState.AddModelError("", "National Park exists!");

                return(StatusCode(404, ModelState));
            }

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

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

            if (!_npRepo.CreateNationalPark(nationalParkObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record {nationalParkObj.Name}");

                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetNationalPark", new { version = HttpContext.GetRequestedApiVersion().ToString(), nationalParkId = nationalParkObj.Id }, nationalParkObj));
        }
Пример #2
0
        public IActionResult CreateNationalPark([FromBody] NationalParkDto nationalParkDto)
        {
            if (nationalParkDto == null)
            {
                return(BadRequest(ModelState));
            }
            if (_npRepo.NationalParkExist(nationalParkDto.Name))
            {
                ModelState.AddModelError("", "National Park Exsist");
                return(StatusCode(404, ModelState));
            }

            NationalPark nationalPark = _mapper.Map <NationalPark>(nationalParkDto);

            if (!_npRepo.CreateNationalPark(nationalPark))
            {
                ModelState.AddModelError("", "Error with saving file");
                return(StatusCode(500, ModelState));
            }
            return(CreatedAtRoute("GetNationalPark", new { version = HttpContext.GetRequestedApiVersion().ToString(), nationalParkId = nationalPark.Id }, nationalPark));
        }
        public IActionResult CreateNationalPark([FromBody] NationalParkDto nationalParkDto)
        {
            if (nationalParkDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (_nationalParkRepository.NationalParkExist(nationalParkDto.Name))
            {
                ModelState.TryAddModelError("", "National Park Exists");
                return(StatusCode(404, ModelState));
            }

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

            if (!_nationalParkRepository.CreateNationalPark(ojbNationalPark))
            {
                ModelState.AddModelError("", $"Something went wrong went creating the recored {ojbNationalPark.Name}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetNationalPark", new { version = HttpContext.GetRequestedApiVersion().ToString(), nationalParkId = ojbNationalPark.Id }, ojbNationalPark));
        }
Пример #4
0
        public IActionResult CreateNationalPark([FromBody] NationalParkDto nationalParkDto)
        {
            if (nationalParkDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (_npRepo.NationalParkExist(nationalParkDto.Name))
            {
                ModelState.AddModelError("", "National Park already exist!");
                return(StatusCode(404, ModelState));
            }

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

            if (!_npRepo.CreateNationalPark(nationalParkObj))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record{nationalParkObj.Name}");
                return(StatusCode(500, ModelState));
            }
            //return Ok();
            return(CreatedAtRoute("GetNationalPark", new { id = nationalParkObj.Id }, nationalParkObj));
        }