コード例 #1
0
 public void Write(QuoteResults quote)
 {
     Console.WriteLine("Requested amount:£{0}", quote.LoanAmount);
     Console.WriteLine("Rate:{0}%", Math.Round(quote.QuoteRate * 100, 1));
     Console.WriteLine("Monthly repayment:£{0}", quote.MonthlyRepayment);
     Console.WriteLine("Total repayment:£{0}", quote.TotalRepayment);
 }
コード例 #2
0
        public async Task <IActionResult> Detail(string symbol)
        {
            QuoteResults responses = await _YahooFinanceClient.Detail(symbol);

            if (responses.QuoteResponse.Result.Count != 1)
            {
                BadRequest($"Only one result was expected bu got {responses.QuoteResponse.Result.Count}");
            }

            QuoteResult result = responses.QuoteResponse.Result[0];

            InstrumentDetailResult retVal = new InstrumentDetailResult();

            retVal.Name     = result.LongName;
            retVal.Symbol   = result.Symbol;
            retVal.Type     = MapQuoteType(result.QuoteType);
            retVal.Exchange = result.Exchange;
            retVal.Currency = result.Currency;

            return(Ok(retVal));
        }
コード例 #3
0
        public async Task <QuoteResults> Detail(string symbol)
        {
            HttpRequestMessage request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri($"https://yfapi.net/v6/finance/quote?region=US&lang=en&symbols={symbol}"),
                Headers    =
                {
                    { "x-api-key", _Configuration.GetValue <string>("financeapi-key") },
                },
            };


            using (HttpResponseMessage response = await _Client.SendAsync(request))
            {
                response.EnsureSuccessStatusCode();

                string json = await response.Content.ReadAsStringAsync();

                QuoteResults results = JsonConvert.DeserializeObject <QuoteResults>(json);

                return(results);
            }
        }
コード例 #4
0
        public ActionResult SignUp(string firstName, string lastName, string emailAddress, string dateofBirth,
                                   string carYear, string carMake, string carModel, string dui, string tickets, string coverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress) ||
                string.IsNullOrEmpty(dateofBirth) || string.IsNullOrEmpty(carYear) || string.IsNullOrEmpty(carMake) ||
                string.IsNullOrEmpty(carModel) || string.IsNullOrEmpty(dui) || string.IsNullOrEmpty(tickets) || string.IsNullOrEmpty(coverage))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                DateTime dob      = DateTime.Parse(dateofBirth);
                Int32    yearoCar = Convert.ToInt32(carYear);
                Int32    tix      = Convert.ToInt32(tickets);
                decimal  result   = 50m;
                DateTime today    = DateTime.Today;
                Int32    age      = today.Year - dob.Year;

                if (age < 25 && age > 18)
                {
                    result += 25;
                }
                if (age < 18)
                {
                    result += 100;
                }
                if (age > 100)
                {
                    result += 25;
                }
                if (yearoCar < 2000)
                {
                    result += 25;
                }
                if (yearoCar > 2015)
                {
                    result += 25;
                }
                if (carMake.ToLower() == "porsche")
                {
                    result += 25;
                }
                if (carMake.ToLower() == "porsche" && carModel == "911")
                {
                    result += 25;
                }
                if (tix > 0)
                {
                    Int32 ticket = tix * 10;
                    result += ticket;
                }
                if (dui.ToLower() == "yes" || dui.ToLower() == "y" || dui.ToLower() == "yeah" || dui.ToLower() == "ya")
                {
                    result = (result * .25m) + result;
                }
                if (coverage.ToLower() == "full")
                {
                    result = (result * .5m) + result;
                }

                string queryString = @"INSERT INTO AutoQuotes (FirstName, LastName, EmailAddress, DateofBirth,
                                       CarYear, CarMake, CarModel, Dui, Tickets, Coverage, Total) VALUES
                                       (@FirstName, @LastName, @EmailAddress, @DateofBirth, @CarYear, @CarMake,
                                        @CarModel, @Dui, @Tickets, @Coverage, @Total)";

                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    SqlCommand command = new SqlCommand(queryString, connection);
                    command.Parameters.Add("@FirstName", SqlDbType.VarChar);
                    command.Parameters.Add("@LastName", SqlDbType.VarChar);
                    command.Parameters.Add("@EmailAddress", SqlDbType.VarChar);
                    command.Parameters.Add("@DateofBirth", SqlDbType.Date);
                    command.Parameters.Add("@CarYear", SqlDbType.Int);
                    command.Parameters.Add("@CarMake", SqlDbType.VarChar);
                    command.Parameters.Add("@CarModel", SqlDbType.VarChar);
                    command.Parameters.Add("@Dui", SqlDbType.VarChar);
                    command.Parameters.Add("@Tickets", SqlDbType.Int);
                    command.Parameters.Add("@Coverage", SqlDbType.VarChar);
                    command.Parameters.Add("@Total", SqlDbType.Decimal);

                    command.Parameters["@FirstName"].Value    = firstName;
                    command.Parameters["@LastName"].Value     = lastName;
                    command.Parameters["@EmailAddress"].Value = emailAddress;
                    command.Parameters["@DateofBirth"].Value  = dateofBirth;
                    command.Parameters["@CarYear"].Value      = carYear;
                    command.Parameters["@CarMake"].Value      = carMake;
                    command.Parameters["@CarModel"].Value     = carModel;
                    command.Parameters["@Dui"].Value          = dui;
                    command.Parameters["@Tickets"].Value      = tickets;
                    command.Parameters["@Coverage"].Value     = coverage;
                    command.Parameters["@Total"].Value        = result;

                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                }
                QuoteResults n = new QuoteResults()
                {
                    FirstName = firstName,
                    LastName  = lastName,
                    Total     = result
                };
                return(View("Results", n));
            }
        }