Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dgkanatsios
Last active October 30, 2016 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgkanatsios/33207c33a0f17caf2730d7029110e18a to your computer and use it in GitHub Desktop.
Save dgkanatsios/33207c33a0f17caf2730d7029110e18a to your computer and use it in GitHub Desktop.
public class BookParkingDialogChain : IDialog<object>
{
private string selectedName, selectedEmail, selectedPhoneNumber;
private string selectedLicensePlate;
private ParkingAreaDetails selectedParkingLocationDetails;
private DateTime arrivalDateTime, departureDateTime;
private ParkingLotDetails selectedParkingLot;
ParkAroundBot.Data.ReserveTravelResponse result;
private bool finalConfirmation;
public async Task StartAsync(IDialogContext context)
{
context.Wait<string>(conversationStarted);
}
private async Task conversationStarted(IDialogContext context, IAwaitable<string> s)
{
await context.PostAsync(StringMessages.Welcome);
var dialog = CreateChain();
context.Call(dialog, ProcessFinished);
}
private IDialog<bool> CreateChain()
{
var dialog = Chain.From(() => new ParkingAreaSelectionDialog())
.ContinueWith<ParkingAreaDetails, DateTime>
(async (ctx, parkinglocationdetails) =>
{
selectedParkingLocationDetails = await parkinglocationdetails;
return new DateTimeInputDialog(null, selectedParkingLocationDetails);
})
.ContinueWith<DateTime, DateTime>
(async (ctx, dt) =>
{
arrivalDateTime = await dt;
return new DateTimeInputDialog(arrivalDateTime, selectedParkingLocationDetails);
})
.ContinueWith<DateTime, ParkingLotDetails>
(async (ctx, dt) =>
{
departureDateTime = await dt;
return new ParkingLotSelectionDialog
(selectedParkingLocationDetails, arrivalDateTime, departureDateTime);
})
.LoopWhile(async (ctx, parkingLot) =>
{
if ((await parkingLot) == null)
return true;
else
return false;
})
.ContinueWith<ParkingLotDetails, string>
(async (ctx, parkingLot) =>
{
selectedParkingLot = await parkingLot;
return new FullnameInputDialog();
})
.ContinueWith<string, string>
(async (ctx, username) =>
{
selectedName = await username;
var emailDialog = CustomTextInputDialog.CreateCustomTextInputDialog
(StringMessages.EnterEmail, StringMessages.EnterEmail, new EmailCustomInputValidator());
return emailDialog;
})
.ContinueWith<string, string>
(async (ctx, email) =>
{
selectedEmail = await email;
var phoneDialog = CustomTextInputDialog.CreateCustomTextInputDialog
(StringMessages.PhoneNumber, StringMessages.PhoneNumber, new PhoneCustomInputValidator());
return phoneDialog;
})
.ContinueWith<string, string>
(async (ctx, phoneNumber) =>
{
selectedPhoneNumber = await phoneNumber;
var licensePlateDialog = CustomTextInputDialog.CreateCustomTextInputDialog
(StringMessages.EnterLicensePlate, StringMessages.EnterCorrectLicensePlate, new TextCustomInputValidator(2, 10));
return licensePlateDialog;
})
.ContinueWith<string, bool>
(async (ctx, licenseplate) =>
{
selectedLicensePlate = await licenseplate;
var confirmationDialog = new ConfirmBookingDialog(selectedParkingLot.parkingLotName, selectedParkingLot.Price, selectedEmail, selectedParkingLot.Image, arrivalDateTime.ToShortDateString(), departureDateTime.ToShortDateString());
return confirmationDialog;
}).ContinueWith<bool, bool>
(async (ctx, confirmation) =>
{
finalConfirmation = await confirmation;
return Chain.Return(finalConfirmation);
});
return dialog;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment