Esempio n. 1
0
        public async Task <IActionResult> UpdateReservation([FromBody] ReservationOnUpdateDto updatedReservation, Guid reservationId)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(420, ModelState));
            }

            await _reservationService.UpdateAsync(updatedReservation, reservationId);

            return(Ok());
        }
Esempio n. 2
0
        public async Task UpdateAsync(ReservationOnUpdateDto reservationDto, Guid reservationId)
        {
            var reservationToUpdate = await _reservationRepository.GetAsync(reservationId);

            if (reservationToUpdate == null)
            {
                throw new ServiceException(ErrorCodes.ReservationNotFound, "Reservation doesn't exist");
            }

            var restaurant = await _restaurantRepository.GetAsync(reservationDto.Restaurant.Id);

            var customer = await _customerRepository.GetAsync(reservationDto.Customer.Login);

            var table = new Table(reservationDto.Table.NumberOfSeats,
                                  reservationDto.Table.Coordinates);

            var updatedReservation = new Reservation(restaurant, reservationDto.DateStart, reservationDto.DateEnd,
                                                     table, customer, reservationDto.IsConfirmed, reservationDto.IsActive);

            await _reservationRepository.UpdateAsync(updatedReservation);
        }