Ejemplo n.º 1
0
        private string Handle(HttpContext context, string action, WebhookSendData data)
        {
            string strResult = string.Empty;

            switch (action)
            {
            case "login":
            {
                Random random   = new Random(Guid.NewGuid().GetHashCode());
                var    accounts = GetLoginAccounts();

                string name     = data.FormValues.FirstOrDefault(a => a.label.Equals("email", StringComparison.InvariantCultureIgnoreCase))?.value;
                string password = data.FormValues.FirstOrDefault(a => a.label.Equals("password", StringComparison.InvariantCultureIgnoreCase))?.value;

                //Name or password is wrong. /Login succeeded.
                string stringResult = "Your email or password is wrong. Login failed.";
                if (accounts.Exists(f => f.Name == name && f.Password == password))
                {
                    stringResult = "Login successfully!";
                }

                strResult = @"[{
  'type': 'text',
  'content': {
    'message': '" + stringResult + @"'
  }
}]";

                break;
            }
            }
            return(strResult);
        }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;

            try
            {
                Stream stream = request.InputStream;
                string json   = string.Empty;
                if (stream.Length != 0)
                {
                    StreamReader streamReader = new StreamReader(stream);
                    json = streamReader.ReadToEnd();
                    WriteLog("input:" + json);
                    WebhookSendData data      = JsonConvert.DeserializeObject <WebhookSendData>(json);
                    string          action    = context.Request.QueryString["action"].ToLower();
                    string          strResult = Handle(context, action, data);

                    context.Response.StatusCode = 200;
                    context.Response.Write(JsonConvert.DeserializeObject <dynamic>(strResult));
                    WriteLog("\n output:" + JsonConvert.SerializeObject(strResult));
                    return;
                }
                context.Response.StatusCode = 400;
                context.Response.Write("request data invaild");
            }
            catch (Exception ex)
            {
                context.Response.StatusCode = 500;
                context.Response.Write(ex.Message);
                WriteLog("exception:" + ex.Message);
            }
        }
Ejemplo n.º 3
0
        private string Handle(HttpContext context, string action, WebhookSendData data)
        {
            string strResult = string.Empty;

            switch (action)
            {
            case "loan":
            {
                string homeValue              = data.FormValues.FirstOrDefault(a => a.label.Equals("home_value", StringComparison.InvariantCultureIgnoreCase))?.value;
                string mortgageBalance        = data.FormValues.FirstOrDefault(a => a.label.Equals("mortgage_balance", StringComparison.InvariantCultureIgnoreCase))?.value;
                string primaryOrSecondaryHome = data.FormValues.FirstOrDefault(a => a.label.Equals("primary_or_secondary", StringComparison.InvariantCultureIgnoreCase))?.value;
                string zipCode = data.FormValues.FirstOrDefault(a => a.label.Equals("sys-zip-code", StringComparison.InvariantCultureIgnoreCase))?.value;

                //loan amount primary (home value-mortgage balance)*0.75
                //secondary (home value-mortgage balance)*0.8

                //Thanks. Based on what you’ve entered, your maximum loan amount would be $150,000.

                var homeValueDec       = decimal.Parse(homeValue?.Replace("$", "").Replace(",", ""));
                var mortgageBalanceDec = decimal.Parse(mortgageBalance?.Replace("$", "").Replace(",", ""));

                var amount = (homeValueDec - mortgageBalanceDec) * 0.75m;
                if (primaryOrSecondaryHome.Equals("secondary", StringComparison.OrdinalIgnoreCase))
                {
                    amount = (homeValueDec - mortgageBalanceDec) * 0.8m;
                }

                var amountStr = string.Format("${0:N0}", amount);

                string stringResult = $"Thanks. Based on what you’ve entered, your maximum loan amount would be {amountStr}.";

                strResult = @"[{
  'type': 'text',
  'content': {
    'message': '" + stringResult + @"'
  }
},{
  'type': 'text',
  'content': {
    'message': 'Would you like me to email you a summary of your home equity loan options? Just tell me your email address if so.'
  }
}]";

                break;
            }
            }
            return(strResult);
        }
        private string Handle(HttpContext context, string action, WebhookSendData data)
        {
            string strResult = string.Empty;

            switch (action)
            {
            case "book":
            {
                Random random = new Random(Guid.NewGuid().GetHashCode());
                List <HappyPizzaBook> accounts = GetBankAccounts();

                string flavor  = data.FormValues.FirstOrDefault(a => a.label.Equals("flavor", StringComparison.InvariantCultureIgnoreCase))?.value;
                string size    = data.FormValues.FirstOrDefault(a => a.label.Equals("size", StringComparison.InvariantCultureIgnoreCase))?.value;
                string type    = data.FormValues.FirstOrDefault(a => a.label.Equals("type", StringComparison.InvariantCultureIgnoreCase))?.value;
                string payment = data.FormValues.FirstOrDefault(a => a.label.Equals("payment", StringComparison.InvariantCultureIgnoreCase))?.value;
                //string orderNo =  Guid.NewGuid().ToString("N").Substring(0, 6);
                string orderNo = random.Next(100000, 999999).ToString();

                accounts.Add(new HappyPizzaBook
                    {
                        orderNo = orderNo,
                        flavor  = flavor,
                        size    = size,
                        type    = type,
                        payment = payment,
                    });

                SaveBankAccounts(accounts);

                //var scheme = context.Request.Url.Scheme;
                //var host = context.Request.Url.Host;
                //var port = context.Request.Url.Port; //{scheme}://{host}:{port}

                var    hostUrl = context.Request.Url.ToString().Substring(0, context.Request.Url.ToString().IndexOf("HappyPizzaBookService"));
                string url     = $"{hostUrl}DonorDemo/index3.html?orderNo={orderNo}";

                strResult = @"[{
  'type': 'text',
  'content': {
    'message': 'Brilliant! Just click this link to enter in your payment details and place your order.',
    'links': [
      {
        'type': 'hyperlink',
        'startPosition': 16,
        'endPosition': 21,
        'ifPushPage': true,
        'url': '" + url + @"',
        'openIn': 'sideWindow'
      }
    ]
  }
}]";

                break;
            }

            case "query":
            {
                List <HappyPizzaBook> accounts = GetBankAccounts();

                string orderNo = data.FormValues.FirstOrDefault(a => a.label.Equals("orderNo", StringComparison.InvariantCultureIgnoreCase))?.value;

                HappyPizzaBook happyPizzaBook = accounts.FirstOrDefault(a => a.orderNo == orderNo);

                if (happyPizzaBook != null)
                {
                    strResult = @"[{
  'type': 'text',
  'content': {
    'message': 'I can see your order is out for delivery now and your delivery person will be in touch shortly if there are any problems.'
  }
}]";
                }
                else
                {
                    strResult = @"[{
  'type': 'text',
  'content': {
    'message': 'Sorry, the order does not exist.'
  }
}]";
                }

                break;
            }

            case "savepayment":
            {
                List <HappyPizzaBook> accounts = GetBankAccounts();

                string orderNo = data.FormValues.FirstOrDefault(a => a.label.Equals("orderNo", StringComparison.InvariantCultureIgnoreCase))?.value;
                string payment = data.FormValues.FirstOrDefault(a => a.label.Equals("payment", StringComparison.InvariantCultureIgnoreCase))?.value;

                HappyPizzaBook happyPizzaBook = accounts.FirstOrDefault(a => a.orderNo == orderNo);
                happyPizzaBook.payment = payment;

                SaveBankAccounts(accounts);

                break;
            }
            }
            return(strResult);
        }
Ejemplo n.º 5
0
        private string Handle(HttpContext context, string action, WebhookSendData data)
        {
            string strResult = string.Empty;

            switch (action)
            {
            case "transfer":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                string fromAccountType = data.FormValues.FirstOrDefault(a => a.label.Equals("from account", StringComparison.InvariantCultureIgnoreCase))?.value; //转出账户类型
                //string toAccountType = data.FormValues.FirstOrDefault(a => a.label.Equals("to account type", StringComparison.InvariantCultureIgnoreCase))?.value;//转入账户类型
                string amount = data.FormValues.FirstOrDefault(a => a.label.Equals("amount", StringComparison.InvariantCultureIgnoreCase))?.value;                //金额
                //string payee = data.FormValues.FirstOrDefault(a => a.label.Equals("payee", StringComparison.InvariantCultureIgnoreCase))?.value;//收款人

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                //BankAccount toBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(payee, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null /*&& toBankAccount != null*/)
                {
                    if (fromAccountType.Equals("Savings", StringComparison.InvariantCultureIgnoreCase))
                    {
                        fromBankAccount.Savings = (decimal.Parse(fromBankAccount.Savings) - decimal.Parse(amount)).ToString("0.00");
                    }
                    else
                    {
                        fromBankAccount.Checking = (decimal.Parse(fromBankAccount.Checking) - decimal.Parse(amount)).ToString("0.00");
                    }

                    //if (toAccountType.Equals("Savings", StringComparison.InvariantCultureIgnoreCase))
                    //{
                    //    toBankAccount.Savings = (decimal.Parse(toBankAccount.Savings) + decimal.Parse(amount)).ToString();
                    //}
                    //else
                    //{
                    //    toBankAccount.Checking = (decimal.Parse(toBankAccount.Checking) + decimal.Parse(amount)).ToString();
                    //}

                    SaveBankAccounts(accounts);
                }

                //strResult = "Placeholder text";
                strResult = string.Format("${0} dollars transferred out your {1} account. Your new checking balance is: ${2}, your new savings balance is ${3}",
                                          amount, fromAccountType, fromBankAccount.Checking, fromBankAccount.Savings);

                break;
            }

            case "transferbetweensavingsandchecking":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                string fromAccountType = data.FormValues.FirstOrDefault(a => a.label.Equals("from account", StringComparison.InvariantCultureIgnoreCase))?.value; //转出账户类型
                string toAccountType   = data.FormValues.FirstOrDefault(a => a.label.Equals("to account", StringComparison.InvariantCultureIgnoreCase))?.value;   //转入账户类型
                string amount          = data.FormValues.FirstOrDefault(a => a.label.Equals("amount", StringComparison.InvariantCultureIgnoreCase))?.value;       //金额

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                BankAccount toBankAccount   = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null && toBankAccount != null)
                {
                    if (fromAccountType.Equals("Savings", StringComparison.InvariantCultureIgnoreCase))
                    {
                        fromBankAccount.Savings = (decimal.Parse(fromBankAccount.Savings) - decimal.Parse(amount)).ToString("0.00");
                    }
                    else
                    {
                        fromBankAccount.Checking = (decimal.Parse(fromBankAccount.Checking) - decimal.Parse(amount)).ToString("0.00");
                    }

                    if (toAccountType.Equals("Savings", StringComparison.InvariantCultureIgnoreCase))
                    {
                        toBankAccount.Savings = (decimal.Parse(toBankAccount.Savings) + decimal.Parse(amount)).ToString("0.00");
                    }
                    else
                    {
                        toBankAccount.Checking = (decimal.Parse(toBankAccount.Checking) + decimal.Parse(amount)).ToString("0.00");
                    }

                    SaveBankAccounts(accounts);
                }

                strResult = string.Format("${0} dollars transferred to your {1} account. Your new checking balance is: ${2}, your new savings balance is ${3}",
                                          amount, toAccountType, toBankAccount.Checking, toBankAccount.Savings);

                break;
            }

            case "confirmaddress":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("The address we have on file for you is {0}. Would you like to change it?", fromBankAccount?.Address);

                break;
            }

            case "confirmphone":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("The phone we have on file for you is {0}. Would you like to change it?", fromBankAccount?.Phone);

                break;
            }

            case "savingsbalance":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                string fromAccountType = data.FormValues.FirstOrDefault(a => a.label.Equals("account", StringComparison.InvariantCultureIgnoreCase))?.value;        //账户类型

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                string      balance         = fromBankAccount?.Savings;
                if (fromBankAccount != null)
                {
                    if (fromAccountType.Equals("Savings", StringComparison.InvariantCultureIgnoreCase))
                    {
                        balance = fromBankAccount?.Savings;
                    }
                    else
                    {
                        balance = fromBankAccount?.Checking;
                    }
                }

                strResult = string.Format("Your balance is ${0}", decimal.Parse(balance).ToString("0.00"));

                break;
            }

            case "accountnumber":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("Your account number is {0}", fromBankAccount?.AccountNumber);

                break;
            }

            case "accountusername":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("Your account username is {0}", fromBankAccount?.Username);

                break;
            }

            case "branchnumber":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("your branch number is {0}", fromBankAccount?.BranchNumber);

                break;
            }

            case "transactionlimits":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("Your daily transaction limit is {0}", fromBankAccount?.DailyTransactionLimit);

                break;
            }

            case "routingnumber":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("Your Routing Number is {0}", fromBankAccount?.RoutingNumber);

                break;
            }

            case "transitnumber":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("Your transit number is {0}", fromBankAccount?.TransitNumber);

                break;
            }

            case "holdpolicy":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("The hold policy on your deposits is {0}", fromBankAccount?.HoldPolicy);

                break;
            }

            case "overdraftpolicy":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (fromBankAccount != null)
                {
                }

                strResult = string.Format("The overdraft policy on your account is {0}", fromBankAccount?.OverdraftPolicy);

                break;
            }

            case "changeaddress":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                string      address         = data.FormValues.FirstOrDefault(a => a.label.Equals("sys-street-address", StringComparison.InvariantCultureIgnoreCase))?.value;//新地址

                if (fromBankAccount != null)
                {
                    fromBankAccount.Address = address;
                    SaveBankAccounts(accounts);
                }

                strResult = string.Format("your new address on file is {0}", address);

                break;
            }

            case "changephone":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                string      phone           = data.FormValues.FirstOrDefault(a => a.label.Equals("Your new phone", StringComparison.InvariantCultureIgnoreCase))?.value;//新电话

                if (fromBankAccount != null)
                {
                    fromBankAccount.Phone = phone;
                    SaveBankAccounts(accounts);
                }

                strResult = string.Format("your new phone number on file is {0}", phone);

                break;
            }

            case "changepassword":
            {
                string             username = data.Visitor.ssoid.ToString();
                List <BankAccount> accounts = GetBankAccounts();

                BankAccount fromBankAccount   = accounts.FirstOrDefault(a => a.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                string      accountNumber     = data.FormValues.FirstOrDefault(a => a.label.Equals("Account number", StringComparison.InvariantCultureIgnoreCase))?.value;
                string      lastName          = data.FormValues.FirstOrDefault(a => a.label.Equals("Last name", StringComparison.InvariantCultureIgnoreCase))?.value;
                string      zipCode           = data.FormValues.FirstOrDefault(a => a.label.Equals("Zip code", StringComparison.InvariantCultureIgnoreCase))?.value;
                string      emailAddress      = data.FormValues.FirstOrDefault(a => a.label.Equals("Email address", StringComparison.InvariantCultureIgnoreCase))?.value;
                string      securityQuestion1 = data.FormValues.FirstOrDefault(a => a.label.Equals("Security question #1", StringComparison.InvariantCultureIgnoreCase))?.value;
                string      securityQuestion2 = data.FormValues.FirstOrDefault(a => a.label.Equals("Security question #2", StringComparison.InvariantCultureIgnoreCase))?.value;
                string      password          = data.FormValues.FirstOrDefault(a => a.label.Equals("New password", StringComparison.InvariantCultureIgnoreCase))?.value;

                if (fromBankAccount != null)
                {
                    if (fromBankAccount.SecurityQuestion2 != securityQuestion2)
                    {
                        strResult = "Your security question #2 is wrong, please try again.";
                    }
                    if (fromBankAccount.SecurityQuestion1 != securityQuestion1)
                    {
                        strResult = "Your security question #1 is wrong, please try again.";
                    }
                    if (fromBankAccount.AccountNumber != accountNumber)
                    {
                        strResult = "Your account number is wrong, please try again.";
                    }

                    if (string.IsNullOrWhiteSpace(strResult))
                    {
                        fromBankAccount.Password = password;
                        SaveBankAccounts(accounts);
                        strResult = string.Format("You password has been changed");
                    }
                }

                break;
            }

            case "atmnearest":
            {
                string username = data.Visitor.ssoid.ToString();

                List <dynamic> atms = new List <dynamic> {
                    new {
                        latitude  = 47.23965880000002,
                        longitude = -122.40253050000001,
                        response  = "The nearest FCB ATM is located at: 2024 E 29th St, Tacoma, WA 98404",
                    },
                    new {
                        latitude  = 48.4718561,
                        longitude = -122.41023940000002,
                        response  = "The nearest ATM location to you is: 15400 Airport Dr, Burlington, WA 98233",
                    },
                    new {
                        latitude  = 47.666490399999994,
                        longitude = -117.40244949999999,
                        response  = "The nearest ATM location to you is: 502 E Boone Ave, Spokane, WA 99258",
                    },
                };

                double latitude  = data.Visitor.latitude;
                double longitude = data.Visitor.longitude;

                double first  = GetDistance(latitude, longitude, atms[0].latitude, atms[0].longitude);
                double second = GetDistance(latitude, longitude, atms[1].latitude, atms[1].longitude);
                double third  = GetDistance(latitude, longitude, atms[2].latitude, atms[2].longitude);

                int    minIndex = 0;
                double min      = first;
                if (first > second)
                {
                    min      = second;
                    minIndex = 1;
                }
                if (min > third)
                {
                    min      = third;
                    minIndex = 2;
                }
                string response = atms[minIndex].response;
                strResult = string.Format(response);

                break;
            }

            case "branchnearest":
            {
                string username = data.Visitor.ssoid.ToString();

                List <dynamic> atms = new List <dynamic> {
                    new {
                        latitude  = 47.654332700000005,
                        longitude = -117.4293462,
                        response  = "The nearest branch to you is: 1111 W 3rd Ave, Spokane, WA 99201",
                    },
                    new {
                        latitude  = 47.5969724,
                        longitude = -122.32901979999997,
                        response  = "The nearest FCB branch to you is: 800 Occidental Ave S, Seattle, WA 98134",
                    },
                    new {
                        latitude  = 48.76304990000005,
                        longitude = -122.463887,
                        response  = "The nearest branch to you is: 2410 James St, Bellingham, WA 98225",
                    },
                };

                double latitude  = data.Visitor.latitude;
                double longitude = data.Visitor.longitude;

                double first  = GetDistance(latitude, longitude, atms[0].latitude, atms[0].longitude);
                double second = GetDistance(latitude, longitude, atms[1].latitude, atms[1].longitude);
                double third  = GetDistance(latitude, longitude, atms[2].latitude, atms[2].longitude);

                int    minIndex = 0;
                double min      = first;
                if (first > second)
                {
                    min      = second;
                    minIndex = 1;
                }
                if (min > third)
                {
                    min      = third;
                    minIndex = 2;
                }
                string response = atms[minIndex].response;
                strResult = string.Format(response);

                break;
            }
            }
            return(strResult);
        }