internal static async Task <Booking> GetNewlyCreatedBookingForTestAsync(Cruise cruise, BookingRepository repository) { var source = GetBookingForTest(GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest(firstName: "Förnamn1", lastName: "Efternamn1"))); var result = await repository.CreateAsync(cruise, source); return(await repository.FindByReferenceAsync(result.Reference)); }
static async Task <BookingResult> CreateBookingFromSource(BookingSource source, BookingRepository repository = null) { if (null == repository) { repository = GetBookingRepositoryForTest(); } var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync(); return(await repository.CreateAsync(cruise, source)); }
public async Task <IHttpActionResult> CreateOrUpdate(BookingSource bookingSource) { try { Cruise activeCruise = await _cruiseRepository.GetActiveAsync(); if (null == activeCruise) { return(NotFound()); } BookingResult result; if (!String.IsNullOrEmpty(bookingSource.Reference)) { if (!AuthContext.IsAdmin && !String.Equals(AuthContext.UserName, bookingSource.Reference, StringComparison.InvariantCultureIgnoreCase)) { return(BadRequest("Request is unauthorized, or not logged in as the booking it's trying to update.")); } result = await _bookingRepository.UpdateAsync(activeCruise, bookingSource, allowUpdateDetails : AuthContext.IsAdmin, allowUpdateIfLocked : AuthContext.IsAdmin); _log.Info("Updated booking {0}.", result.Reference); } else { result = await _bookingRepository.CreateAsync(activeCruise, bookingSource, allowCreateIfLocked : AuthContext.IsAdmin); _log.Info("Created booking {0}.", result.Reference); await SendBookingCreatedMailAsync(activeCruise, bookingSource, result); } // Ensure we update reporting after each change HostingEnvironment.QueueBackgroundWorkItem(ct => _reportingService.GenerateReportsAsync()); return(Ok(result)); } catch (AvailabilityException ex) { _log.Info(ex, "Lack of availability prevented a booking from being created."); return(Conflict()); } catch (BookingException ex) { _log.Warn(ex, "A validation error occurred while creating the booking."); return(BadRequest(ex.Message)); } catch (Exception ex) { _log.Error(ex, "An unexpected exception occurred while creating the booking."); throw; } }
public async Task <Booking> CreateAsync(string startTime, string endTime, long customerId) { var customer = await _customerServiceApiClient.GetCustomerByIdAsync(customerId, _correlationContext.CorrelationContext.CorrelationId); var booking = new Booking(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), customerId, customer.FirstName); await _bookingRepository.CreateAsync(booking); await _bookingRepository.SaveChangesAsync(); var @event = booking.Adapt <CreatedBookingEvent>(); _eventBus.Publish(@event); return(booking); }