public async Task SyncDeparturesAsync(Crossing crossing, DateTime date, int days, CancellationToken cancellationToken = default) { var vehicleResults = new Dictionary <DateTime, DepartureInfo[]>(); var vehicles = ((Vehicle[])Enum.GetValues(typeof(Vehicle))).Where(x => x.GetAttribute().IncludeInAvailability); await Task.WhenAll(vehicles.Select(async vehicle => { cancellationToken.ThrowIfCancellationRequested(); using (var session = _browserSessionFactory.CreateSession()) { var bookingDetails = await session.GoToAsync <BookingDetailsPage>(); await bookingDetails.EnterDetailsAsync(crossing, vehicle, date); var departureSelect = await session.GoToAsync <DepartureSelectPage>(); var departures = await departureSelect.GetDeparturesAsync(date, days, cancellationToken); lock (vehicleResults) { PatchAvailability(vehicleResults, vehicle, departures); } } })); await Task.WhenAll(vehicleResults.Select(x => _cache.SetDeparturesAsync(crossing, x.Key, x.Value, cancellationToken))); }
public async Task <IActionResult> Cancel(string bookingNumber, [Required] string bookingPassword) { using (var driver = _browserSessionFactory.CreateSession()) { var myBookingPage = await driver.GoToAsync <MyBookingPage>(); await myBookingPage.LoginAsync(bookingNumber, bookingPassword); await myBookingPage.CancelAsync(); return(NoContent()); } }
public async Task <IActionResult> BookItRoundTrip([Required][FromBody] BookRoundTrip command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var session = _browserSessionFactory.CreateSession()) { var loginPage = await session.GoToAsync <LoginPage>(); await loginPage.LoginAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value, User.FindFirst(ClaimTypes.Authentication).Value); var bookingDetailsPage = await session.GoToAsync <BookDetailsPage>(); await bookingDetailsPage.EnterDetailsAsync(command.Outbound, command.Return); var departureSelectPage = await session.GoToAsync <BookDepartureSelectPage>(); await departureSelectPage.SelectDeparturesAsync(command.Outbound.Departure.Value, command.Return.Departure.Value); var contactInformationPage = await session.GoToAsync <BookContantInformationPage>(); await contactInformationPage.EnterInformationAndCheckTermsAsync(command.Customer.FirstName, command.Customer.LastName, command.Customer.PhoneNumber, command.Customer.Email); var bookingConfiguration = await session.GoToAsync <BookConfirmationPage>(); var details = await bookingConfiguration.GetBookingDetailsAsync(); var result = new BookSuccessResult { BookingNumber = details.BookingNumber, BookingPassword = details.BookingPassword, TotalPrice = details.TotalPrice }; return(Ok(result)); } }