public static ValidateResult ValidateInterestRate(Calculation_v2Form state, object value)
        {
            var result = new ValidateResult {
                IsValid = true, Value = value
            };

            var match = Regex.Match((string)value, @"([-+]?[0-9]*\.?[0-9]+)");

            if (match.Success)
            {
                if (NumberIsPositive(Double.Parse(match.Groups[1].Value)))
                {
                    result.Value = match.Groups[1].Value;
                }
                else
                {
                    result.Feedback = "The interest rate must be a positive number.";
                    result.IsValid  = false;
                }
            }
            else
            {
                result.Feedback = "The interest rate must be a positive number.";
                result.IsValid  = false;
            }

            return(result);
        }
        public static ValidateResult ValidatePaymentAmount(Calculation_v2Form state, object value)
        {
            var result = new ValidateResult {
                IsValid = true, Value = value
            };

            var matches = Regex.Matches((string)value, @"(-?\d+)");

            if (matches.Count > 0)
            {
                var values        = matches.Cast <Group>().Select(t => t.Value);
                var paymentAmount = String.Join("", values);
                var parsedNumber  = Double.Parse(paymentAmount);
                if (NumberIsPositive(parsedNumber))
                {
                    result.Value = paymentAmount;
                }
                else
                {
                    result.Feedback = "The amount financed must be a positive number.";
                    result.IsValid  = false;
                }
            }
            else
            {
                result.Feedback = "The amount financed must be a positive number.";
                result.IsValid  = false;
            }

            return(result);
        }
        public Task <Models.Response.Calculation_v2> CallCalculations_v2Api(Calculation_v2Form extractedCalculationForm)
        {
            //Mocked out this code
            var result = new Models.Response.Calculation_v2()
            {
                PaymentAmount = 12345
            };

            return(Task.FromResult(result));
        }
        public async Task CalculateInterest(IDialogContext context, LuisResult result)
        {
            Trace.TraceInformation(DateTime.Now + " Starting finance calculation for " + context.Activity.ChannelId + " for converstation " + context.Activity.Conversation.Id);

            await _chat.PostAsync(context, BotResponses.RootLuisDialog_CalculateInterest);

            var calculation_v2Form       = new Calculation_v2Form();
            var calculation_v2FormDialog = new FormDialog <Calculation_v2Form>(calculation_v2Form, Calculation_v2Form.BuildForm, FormOptions.PromptInStart, result.Entities, CultureInfo.InvariantCulture);

            Trace.TraceInformation(DateTime.Now + " Starting FormFlow");
            context.Call(calculation_v2FormDialog, ResumeAfterCalculation_v2FormDialog);
        }
        internal static ValidateResult ValidateNumberOfMonths(Calculation_v2Form state, object value)
        {
            var result = new ValidateResult {
                IsValid = true, Value = value
            };
            var valueAsString = (string)value;
            var match         = Regex.Match(valueAsString, @"-?\d+");

            if (match.Success)
            {
                int durationNumber = Int32.Parse(match.Value);
                if (NumberIsPositive(durationNumber))
                {
                    int inMonths;
                    if (valueAsString.Contains("year"))
                    {
                        inMonths = (durationNumber * 12);
                    }
                    else
                    {
                        inMonths = durationNumber;
                    }
                    if (inMonths <= 120)
                    {
                        result.Value = inMonths.ToString();
                    }
                    else
                    {
                        result.Feedback = "The number of months must be smaller than 120.";
                        result.IsValid  = false;
                    }
                }
                else
                {
                    result.Feedback = "The number of months must be a positive number.";
                    result.IsValid  = false;
                }
            }
            else
            {
                result.Feedback = "The number of months must be a positive number.";
                result.IsValid  = false;
            }

            return(result);
        }