Esempio n. 1
0
        public IActionResult CreateTrip([FromBody] TripForCreationDto newTrip)
        {
            if (newTrip == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }
            var tripEntity = CustomMapper.MapTripDtoToTrip(newTrip);

            TripsRepository.AddTrip(tripEntity);

            if (!TripsRepository.Save())
            {
                throw new System.Exception("Creating an wish trip failed on save.");
            }

            // var newTripToReturn = CustomMapper.MapTripTripDto(tripEntity);

            return(CreatedAtRoute("GetTrip",
                                  new { id = tripEntity.Id }, null
                                  ));
        }
Esempio n. 2
0
        Trip IConverter.MapTripDtoToTrip(TripForCreationDto value)
        {
            Trip nuevoViaje = new Trip()
            {
                DateVisited = value.VisitedDate,
                IdCountry   = value.IdPais,
                TravelerId  = 10
            };

            return(nuevoViaje);
        }