public HttpResponseMessage SaveNewBooking(Booking newBooking) { BookingsService bookingService = new BookingsService(_logger, _bookingsRepository, _roomsRepository, _locationsRepository, _directoryService); try { User currentUser = _directoryService.GetCurrentUser(User.Identity.Name); if (currentUser == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "User not found in Active Directory. " + User.Identity.Name)); } bookingService.SaveNewBooking(newBooking, currentUser, ConfigurationManager.AppSettings); return(new HttpResponseMessage(HttpStatusCode.OK)); } catch (BookingsService.BookingConflictException e) { var clashedBookingsString = new JavaScriptSerializer().Serialize(ConvertBookingsToDTOs(e.clashedBookings)); return(Request.CreateErrorResponse(HttpStatusCode.Conflict, clashedBookingsString)); } catch (DAL.BookingConflictException e) { _logger.FatalException("Unable to save new booking: " + newBooking.Owner + "/" + newBooking.StartDate, e); return(Request.CreateResponse(HttpStatusCode.NotAcceptable, e.Message)); } catch (ClashedBookingsException e) { var clashedBookingsString = new JavaScriptSerializer().Serialize(ConvertBookingsToDTOs(e.clashedBookings)); return(Request.CreateErrorResponse(HttpStatusCode.BadGateway, clashedBookingsString)); } catch (UnauthorisedOverwriteException e) { return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Unauthorised to overwrite bookings.")); } catch (Exception e) { _logger.FatalException("Unable to save new booking: " + newBooking.Owner + "/" + newBooking.StartDate, e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }