Example #1
0
        public async Task <Reservation> Add(Reservation reservationIn)
        {
            var validDuration = await ValidateReservationDuration(reservationIn);

            if (!validDuration)
            {
                throw new ReservationServiceException(_errorHandler.GetMessage(ErrorMessagesEnum.MaximumDurationExceeded)
                                                      , new string[] { nameof(Reservation.End) });
            }

            var availability = await _reservationRepository.CheckResourceAvailability(reservationIn.Start, reservationIn.End, reservationIn.ResourceId);

            if (!availability)
            {
                throw new ReservationServiceException(_errorHandler.GetMessage(ErrorMessagesEnum.NotAvailable)
                                                      , new string[] { nameof(Reservation.Start), nameof(Reservation.End) });
            }
            await _reservationRepository.Add(reservationIn);

            return(reservationIn);
        }