Пример #1
0
        public IActionResult StockstoInvest(string symbol)
        {
            string         IEXTrading_API_PATH = BASE_URL + "stock/" + symbol + "/quote";
            string         quote = "";
            StockstoInvest obj   = new StockstoInvest();

            // connect to the IEXTrading API and retrieve information
            httpClient.BaseAddress = new Uri(IEXTrading_API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(IEXTrading_API_PATH).GetAwaiter().GetResult();

            // read the Json objects in the API response
            if (response.IsSuccessStatusCode)
            {
                quote = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            }

            // now, parse the Json strings as C# objects
            if (!quote.Equals(""))
            {
                int start = quote.IndexOf("{");
                int end   = quote.IndexOf("}");
                quote = quote.Substring(start, end + 1);
                // https://stackoverflow.com/a/46280739
                //JObject result = JsonConvert.DeserializeObject<JObject>(companyList);
                obj = JsonConvert.DeserializeObject <StockstoInvest>(quote);
            }

            //  CompaniesNews companiesNews = getCompaniesNews(news);

            CompaniestoInvest companiestoinvest = getCompaniestoInvest(obj);

            return(View(companiestoinvest));
        }
Пример #2
0
        public CompaniestoInvest getCompaniestoInvest(StockstoInvest cs)
        {
            List <Company> companies = dbContext.Companies.ToList();

            return(new CompaniestoInvest(companies, cs));
        }