/*
         *  Save the Symbol financial data in the database
         */
        public void PopulateSymbolFinancialData(SymbolFinancial symbolFinancial, String symbol)
        {
            // Database will give PK constraint violation error when trying to insert record with existing PK.
            // So add financial data only if it doesnt exist
            // check existence using symbol (Composite PK) and reportDate (Composite  PK)

            SymbolFinancial sym = new SymbolFinancial();

            sym.symbol = symbol;
            if (dbContext.SymbolFinancials.Where(c => c.symbol.Equals(symbol)).Count() == 0)
            {
                dbContext.SymbolFinancials.Add(sym);
            }
            dbContext.SaveChanges();

            if (symbolFinancial.financials == null)
            {
                return;
            }

            foreach (Financials fin in symbolFinancial.financials)
            {
                if (dbContext.Financials.Where(c => c.symbol.Equals(symbol) &&
                                               c.reportdate.Equals(fin.reportdate)).Count() == 0)
                {
                    fin.symbol = symbol;
                    dbContext.Financials.Add(fin);
                }
                dbContext.SaveChanges();
            }
        }
        /*
         * Calls the IEX reference API to get the financials stats.
         * Returns Financials of the companies whose information is available.
         */
        public SymbolFinancial GetFinancials(String symbol)
        {
            string          IEXTrading_API_PATH = BASE_URL + "stock/" + symbol + "/financials";
            string          responseFinancials  = "";
            SymbolFinancial symbolFinancial     = null;

            // connect to the IEXTrading Financial 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 Financial API response
            if (response.IsSuccessStatusCode)
            {
                responseFinancials = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                Console.WriteLine(responseFinancials);
            }

            // now, parse the Json strings as C# objects
            if (!responseFinancials.Equals(""))
            {
                //chartData = JsonConvert.DeserializeObject<List<Chart>>(responseChartData);
                try
                {
                    symbolFinancial = JsonConvert.DeserializeObject <SymbolFinancial>(responseFinancials);
                }
                catch (Exception ex)
                {
                    symbolFinancial = new SymbolFinancial();
                }
            }

            return(symbolFinancial);
        }
        public IActionResult Financials(String symbol)
        {
            SymbolFinancial financials = GetFinancials(symbol);

            PopulateSymbolFinancialData(financials, symbol);

            List <Financials> financialList = financials.financials;

            return(View(financialList));
        }
Beispiel #4
0
 /*
  *  Save the Symboll financial data in the database
  */
 public void PopulateSymbolFinancialData(SymbolFinancial symbolFinancial)
 {
     //Database will give PK constraint violation error when trying to insert record with existing PK.
     //So add company only if it doesnt exist, check existence using symbol (PK)
     if (dbContext.SymbolFinancials.Where(c => c.symbol.Equals(symbolFinancial.symbol)).Count() == 0)
     {
         dbContext.SymbolFinancials.Add(symbolFinancial);
     }
     dbContext.SaveChanges();
 }