Example #1
0
        public IActionResult CreateTraveler([FromBody] API.Models.TravelerForCreationDto traveler)
        {
            if (traveler == null)
            {
                return(BadRequest());
            }

            var travelerdb = _libraryRepository.GetTraveler(traveler.ClientId);

            if (travelerdb != null)
            {
                return(StatusCode(409));
            }

            var travelerEntity = CustomMapper.MapTravelerForCreationToTravelerDto(traveler);

            _libraryRepository.AddTraveler(travelerEntity);



            if (!_libraryRepository.Save())
            {
                throw new System.Exception("Creating an traveler failed on save.");
            }

            TravelerDto travelerToReturn = CustomMapper.TravelerRepoToTravelerUI(travelerEntity);

            return(CreatedAtRoute("GetTraveler",
                                  new { id = travelerToReturn.Id },
                                  travelerToReturn));
        }