diff --git a/CSharp/cards-AdaptiveCards/AdaptiveCards.csproj b/CSharp/cards-AdaptiveCards/AdaptiveCards.csproj index efb9bc21cf..9ae867218a 100644 --- a/CSharp/cards-AdaptiveCards/AdaptiveCards.csproj +++ b/CSharp/cards-AdaptiveCards/AdaptiveCards.csproj @@ -121,7 +121,6 @@ - diff --git a/CSharp/cards-AdaptiveCards/Dialogs/FlightsDialog.cs b/CSharp/cards-AdaptiveCards/Dialogs/FlightsDialog.cs deleted file mode 100644 index 0a68d3b1a1..0000000000 --- a/CSharp/cards-AdaptiveCards/Dialogs/FlightsDialog.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace BotBuilder.Samples.AdaptiveCards -{ - using Microsoft.Bot.Builder.Dialogs; - using System; - using System.Threading.Tasks; - - [Serializable] - public class FlightsDialog : IDialog - { - public async Task StartAsync(IDialogContext context) - { - context.Fail(new NotImplementedException("Flights Dialog is not implemented and is instead being used to show context.Fail")); - } - } -} \ No newline at end of file diff --git a/CSharp/cards-AdaptiveCards/Dialogs/HotelsDialog.cs b/CSharp/cards-AdaptiveCards/Dialogs/HotelsDialog.cs index b62b7e9412..f4c63eec25 100644 --- a/CSharp/cards-AdaptiveCards/Dialogs/HotelsDialog.cs +++ b/CSharp/cards-AdaptiveCards/Dialogs/HotelsDialog.cs @@ -26,8 +26,7 @@ public async Task StartAsync(IDialogContext context) } catch (FormCanceledException ex) { - string reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}"; - await context.PostAsync(reply); + await context.PostAsync($"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}"); } } @@ -66,8 +65,7 @@ private async Task SearchHotels(IDialogContext context, HotelsQuery searchQuery) }; var reply = context.MakeMessage(); - var attachments = reply.Attachments = new List(); - attachments.Add(attachment); + reply.Attachments.Add(attachment); await context.PostAsync(reply); } diff --git a/CSharp/cards-AdaptiveCards/Dialogs/RootDialog.cs b/CSharp/cards-AdaptiveCards/Dialogs/RootDialog.cs index 865bdf423e..3b82e0caef 100644 --- a/CSharp/cards-AdaptiveCards/Dialogs/RootDialog.cs +++ b/CSharp/cards-AdaptiveCards/Dialogs/RootDialog.cs @@ -31,43 +31,40 @@ public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitabl { // Got an Action Submit dynamic value = message.Value; - if (value.Type == "HotelSearch") + switch(value.Type.ToString()) { - // Hotel Search - HotelsQuery query; - try - { - query = HotelsQuery.Parse(value); - List results = new List(); - bool valid = Validator.TryValidateObject(query, new ValidationContext(query, null, null), results, true); - if (!valid) + case "HotelSearch": + HotelsQuery query; + try { - // Some field in the Hotel Query are not valid - var errors = string.Join("\n", results.Select(o => " - " + o.ErrorMessage)); - var reply = context.MakeMessage(); - reply.Text = "Please complete all the search parameters:\n" + errors; - await context.PostAsync(reply); + query = HotelsQuery.Parse(value); + List results = new List(); + bool valid = Validator.TryValidateObject(query, new ValidationContext(query, null, null), results, true); + if (!valid) + { + // Some field in the Hotel Query are not valid + var errors = string.Join("\n", results.Select(o => " - " + o.ErrorMessage)); + await context.PostAsync("Please complete all the search parameters:\n" + errors); + return; + } + } + catch (InvalidCastException) + { + // Hotel Query could not be parsed + await context.PostAsync("Please complete all the search parameters"); return; } - } - catch (InvalidCastException) - { - // Hotel Query could not be parsed - var reply = context.MakeMessage(); - reply.Text = "Please complete all the search parameters"; - await context.PostAsync(reply); + + // Proceed with hotels search + await context.Forward(new HotelsDialog(), this.ResumeAfterOptionDialog, message, CancellationToken.None); + return; - } - // Proceed with hotels search - await context.Forward(new HotelsDialog(), this.ResumeAfterOptionDialog, message, CancellationToken.None); - } - else if (value.Type == "HotelSelection") - { - // Hotel Selected - await SendHotelSelectionAsync(context, (Hotel)JsonConvert.DeserializeObject(value.ToString())); - context.Wait(MessageReceivedAsync); - return; + case "HotelSelection": + await SendHotelSelectionAsync(context, (Hotel)JsonConvert.DeserializeObject(value.ToString())); + context.Wait(MessageReceivedAsync); + + return; } } @@ -167,8 +164,7 @@ private async Task ShowOptionsAsync(IDialogContext context) }; var reply = context.MakeMessage(); - var attachments = reply.Attachments = new List(); - attachments.Add(attachment); + reply.Attachments.Add(attachment); await context.PostAsync(reply, CancellationToken.None); @@ -288,8 +284,7 @@ private static async Task SendHotelSelectionAsync(IDialogContext context, Hotel }; var reply = context.MakeMessage(); - var attachments = reply.Attachments = new List(); - attachments.Add(attachment); + reply.Attachments.Add(attachment); await context.PostAsync(reply, CancellationToken.None); }