Example #1
0
        public IActionResult UpdateReservation(int id, [FromBody] ReservationForUpdateDto reservation)
        {
            try
            {
                if (reservation == null)
                {
                    _logger.LogError("reservation object sent from client is null.");
                    return(BadRequest("reservation object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid reservation object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                var reservationEntity = _repository.Reservation.GetReservationById(id);
                if (reservationEntity == null)
                {
                    _logger.LogError($"reservation with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }

                _mapper.Map(reservation, reservationEntity);

                _repository.Reservation.UpdateReservation(reservationEntity);
                _repository.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateReservation action: {ex.InnerException.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <IActionResult> Put(int id, [FromBody] ReservationForUpdateDto reservationForUpdateDto)
        {
            if (reservationForUpdateDto == null)
            {
                return(BadRequest());
            }

            var reservationDto = await _reservationAppService.Update(id, reservationForUpdateDto);

            return(CreatedAtRoute(GetReservationActionName, new { id = reservationDto.Id }, reservationDto));
        }
        public async Task <ReservationDto> Update(int id, ReservationForUpdateDto input)
        {
            var reservation = _mapper.Map <Reservation>(input);

            reservation.Id = id;

            await _repository.Update(reservation);

            var output = _mapper.Map <ReservationDto>(reservation);

            return(output);
        }