private async Task ResumeAfterMotorQuoteFormDialog(IDialogContext context, IAwaitable <MotorQuote> result) { var state = await result; var reply = context.MakeMessage(); try { var quoteRepository = new QuoteRepository(Connection); var conversationRepository = new ConversationRepository(Connection); var motorService = new Common.RelayFullCycleMotorService.RelayFullCycleMotorService(); var riskData = MotorQuote.BuildIrishMQRiskInfo(state); var messageRequestInfo = MotorQuote.BuildMessageRequestInfo(); var quotes = motorService.GetNewBusinessXBreakDownsSpecified(riskData, 100, true, null, messageRequestInfo); if (quotes.Quotations != null) { if (quotes.Quotations.Length > 0) { quoteRepository.StoreQuote ( context.Activity.Conversation.Id, quotes.TransactionID, new JavaScriptSerializer().Serialize(quotes.Quotations[0]) ); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = GetQuoteReceipts(quotes.Quotations); if (SendEmails) { var emailToUserBody = EmailHandler.BuildMotorEmailBodyForUser(quotes.Quotations, state.FirstName, state.LastName, state.DateOfBirth, state.PrimaryContactNumber, state.EmailAddress, state.VehicleRegistration, state.Vehicle.Description, state.VehicleValue, state.AreaVehicleIsKept, state.LicenceType.GetDescription(), state.NoClaimsDiscount.GetDescription()); EmailHandler.SendEmailToUser(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailToUserBody); var emailToBrokerBody = EmailHandler.BuildMotorEmailBodyForBroker(quotes.Quotations, state.FirstName, state.LastName, state.DateOfBirth, state.PrimaryContactNumber, state.EmailAddress, state.VehicleRegistration, state.Vehicle.Description, state.VehicleValue, state.AreaVehicleIsKept, state.LicenceType.GetDescription(), state.NoClaimsDiscount.GetDescription()); EmailHandler.SendEmailToBroker(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailToBrokerBody); } await context.PostAsync(reply); } } else { await context.PostAsync("Sorry, we were unable to get your a quote at this point."); } conversationRepository.StoreConversation ( context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(new CultureInfo("en-GB")), new JavaScriptSerializer().Serialize(context) ); } catch (Exception exception) { ErrorRepository.LogError(context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(new CultureInfo("en-GB")), context.ConversationData.ToString(), exception.ToString()); throw; } finally { context.Done(state); } }