コード例 #1
0
        public async Task <ActionResult <TripsDto> > Put(int tripId, TripsDto dto)
        {
            try
            {
                var oldtrip = await _eventRepository.GetTrip(tripId);

                if (oldtrip == null)
                {
                    return(NotFound($"Could not find trip with id {tripId}"));
                }

                var newtrip = _mapper.Map(dto, oldtrip);
                _eventRepository.Update(newtrip);
                if (await _eventRepository.Save())
                {
                    return(NoContent());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
コード例 #2
0
        public async Task <ActionResult <TripsDto> > Post(TripsDto dto)
        {
            try
            {
                var mappedEntity = _mapper.Map <Trips>(dto);
                _eventRepository.Add(mappedEntity);

                if (await _eventRepository.Save())
                {
                    var location = _linkGenerator.GetPathByAction("Get", "Trips", new { mappedEntity.Id });
                    return(Created(location, _mapper.Map <TripsDto>(mappedEntity)));
                }
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException.Message));
            }

            return(BadRequest());
        }