Example #1
0
        public HttpResponseMessage EditExistingBooking(int existingBookingId, Booking editBooking, bool?recurrence = false)
        {
            //Find Existing Booking
            Booking existingBooking = _bookingsRepository.GetById(existingBookingId);

            try
            {
                User currentUser = _directoryService.GetCurrentUser(User.Identity.Name);
                _logger.Debug($"CurrentUser: {currentUser?.FullName}");
                if (currentUser == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "User not found in Active Directory. " + User.Identity.Name));
                }

                _bookingService.EditExistingBooking(existingBooking, editBooking, recurrence, currentUser, ConfigurationManager.AppSettings);
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (UnableToEditBookingException e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "An error occured whilst updating the booking(s). Please try again or contact Service Desk"));
            }
            catch (DAL.BookingConflictException ex)
            {
                _logger.FatalException("Unable to edit booking: " + editBooking.Owner + "/ id: " + editBooking.ID, ex);
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable, ex.Message));
            }
            catch (Exception ex)
            {
                _logger.FatalException("Unable to edit booking: " + editBooking.Owner + "/ id: " + editBooking.ID, ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }