Example #1
0
        public IActionResult Create([FromBody] TrailUpsertDTO trailDTO)
        {
            if (trailDTO == null)
            {
                return(BadRequest());
            }
            if (_trailRepository.ExsistsByName(trailDTO.Name))
            {
                ModelState.AddModelError("", "National Park exsists");
                return(StatusCode(404, ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var trail = _mapper.Map <Trail>(trailDTO);

            if (!_trailRepository.Create(trail))
            {
                ModelState.AddModelError("", $"Something went wrong when saving the record {trail.Name} ");
                return(StatusCode(500, ModelState));
            }
            return(Ok());
        }