예제 #1
0
        public static Vehicle GetVehicle(string vehicleRegistration)
        {
            var vehicle = new Vehicle();

            try
            {
                vehicle.AbiCode = motorService.GetVehicleLookup(
                    vehicleRegistration,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    "RE0098",
                    "relay1:0099",
                    VehicleLookup.Motor).ABICode;

                if (!string.IsNullOrEmpty(vehicle.AbiCode))
                {
                    vehicle = GetVehicleDetails(vehicle.AbiCode);
                }
            }
            catch (Exception exception)
            {
                _errorRepository.LogError(DateTime.Now.ToString(new CultureInfo("en-GB")), exception.ToString());
                throw;
            }

            return(vehicle);
        }
예제 #2
0
        public ValidateResult ValidateDateOfBirth(object value)
        {
            var result = new ValidateResult
            {
                IsValid = false
            };

            try
            {
                CultureInfo culture = new CultureInfo("en-GB");
                var         date    = Convert.ToDateTime(value, culture);

                if (IsProposerOfLegalDrivingAge(date))
                {
                    result.IsValid = true;
                    result.Value   = value.ToString();
                }
                else
                {
                    result.Feedback = "Sorry, but we can't quote for anyone under the age of 17";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ErrorRepository.LogError(DateTime.Now.ToShortDateString(), ex.InnerException.ToString());
                throw;
            }

            return(result);
        }
        public async void StoreConversation(string conversationId, string userId, string conversationDate, string conversationLog)
        {
            try
            {
                using (var connection = new SqlConnection(Connection))
                {
                    await connection.OpenAsync();

                    var conversation = new Conversation
                                       (
                        conversationId,
                        userId,
                        conversationDate,
                        conversationLog
                                       );

                    await connection.ExecuteAsync(
                        "usp_Add_Conversation",
                        conversation,
                        null, null,
                        CommandType.StoredProcedure);
                }
            }
            catch (Exception exception)
            {
                var errorRepository = new ErrorRepository(Connection);
                errorRepository.LogError(conversationId, userId, DateTime.Now.ToString(), conversationLog, exception.ToString());
                throw;
            }
        }
예제 #4
0
        private static Attachment GetReceiptCard(HomeQuoteWebServiceResult homeQuoteWebServiceResult)
        {
            try
            {
                var receiptCard = new ReceiptCard
                {
                    Title = $"{homeQuoteWebServiceResult.InsurerName}",
                    Facts = new List <Fact> {
                        new Fact("Scheme", homeQuoteWebServiceResult.SchemeName)
                    },
                    Tax     = $"€{homeQuoteWebServiceResult.GovernmentLevyPremium}",
                    Total   = $"€{homeQuoteWebServiceResult.NetPremium}",
                    Buttons = new List <CardAction>
                    {
                        new CardAction
                        (
                            ActionTypes.PostBack,
                            "Request a Callback"
                        )
                    }
                };

                return(receiptCard.ToAttachment());
            }
            catch (Exception exception)
            {
                ErrorRepository.LogError(DateTime.Now.ToString(new CultureInfo("en-GB")), exception.ToString());
                throw;
            }
        }
 public bool LogToErrorLog(Exception ex, String url)
 {
     try
     {
         var helper = _helper ?? ConnectionHelper.Helper();
         var repo   = new ErrorRepository(helper);
         repo.LogError(ex, url, -1, Names.Application.PerformanceDashboard);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #6
0
        private static async Task ResumeAfterHomeQuoteFormDialog(IDialogContext context, IAwaitable <HomeQuote> result)
        {
            var state = await result;

            try
            {
                var quoteRepository        = new QuoteRepository(Connection);
                var conversationRepository = new ConversationRepository(Connection);
                var reply = context.MakeMessage();

                var homeService           = new Household();
                var homeWebServiceRequest = HomeQuote.BuildHomeWebServiceRequest(state);

                var quotes   = new List <HomeQuoteWebServiceResult>();
                var response = homeService.GetQuotes(homeWebServiceRequest);

                if (response.Quotes != null)
                {
                    foreach (var quote in response.Quotes)
                    {
                        quotes.Add(quote);
                    }

                    reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    reply.Attachments      = GetQuoteReceipts(quotes);

                    quoteRepository.StoreQuote
                    (
                        context.Activity.Conversation.Id,
                        response.Quotes[0].RelayQuoteId,
                        new JavaScriptSerializer().Serialize(quotes)
                    );
                }
                else
                {
                    reply.Text = "Sorry, we couldn't get any quotes for you.";
                }

                await context.PostAsync(reply);

                if (SendEmails)
                {
                    var emailBodyForUser = EmailHandler.BuildHomeEmailBodyForUser(response.Quotes, state.FirstName, state.LastName, state.PrimaryContactNumber, state.EmailAddress,
                                                                                  state.FirstLineOfAddress, state.Town, state.County, state.PropertyType.GetDescription(), state.ResidenceType.GetDescription(), state.YearBuilt,
                                                                                  state.NumberOfBedrooms.ToString());
                    EmailHandler.SendEmailToUser(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailBodyForUser);
                    var emailBodyForBroker = EmailHandler.BuildHomeEmailBodyForBroker(response.Quotes, state.FirstName, state.LastName, state.PrimaryContactNumber, state.EmailAddress,
                                                                                      state.FirstLineOfAddress, state.Town, state.County, state.PropertyType.GetDescription(), state.ResidenceType.GetDescription(), state.YearBuilt,
                                                                                      state.NumberOfBedrooms.ToString());
                    EmailHandler.SendEmailToBroker(state.EmailAddress, $"{state.FirstName} {state.LastName}", emailBodyForBroker);
                }

                conversationRepository.StoreConversation
                (
                    context.Activity.Conversation.Id,
                    context.Activity.From.Id,
                    DateTime.Now.ToString(new CultureInfo("en-GB")),
                    new JavaScriptSerializer().Serialize(context)
                );
            }
            catch (Exception exception)
            {
                var errorRepository = new ErrorRepository(Connection);
                errorRepository.LogError(context.Activity.Conversation.Id, context.Activity.From.Id, DateTime.Now.ToString(), context.ConversationData.ToString(), exception.ToString());
                throw;
            }
            finally
            {
                context.Done(state);
            }
        }
예제 #7
0
        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);
            }
        }