/*---------------------------------------------------------------------------------------------------*/ /*--------------------------------- Dividends API!!!-------------------------------------------------*/ public IActionResult Dividend(string symbol) { //Set ViewBag variable first ViewBag.dbSuccessChart = 0; List <Dividend> diviends = new List <Dividend>(); if (symbol != null) { diviends = GetDividends(symbol); } DividendVM diviendViewModel = getDividendVM(diviends); return(View(diviendViewModel)); }
/*--------------------------------------------------------------Dividends API Endpoint---------------------------------------------------------------------------*/ /*------------------------------------------------------------- Dividend Action Method---------------------------------------------------------------------------*/ //Dividends API public IActionResult Dividend(string symbol) { //Viewbag initiation ViewBag.dbSuccessChart = 0; List <Dividend> dividends = new List <Dividend>(); if (symbol != null) { dividends = GetDividends(symbol); } DividendVM ReturnedDividends = getDividendVM(dividends); return(View(ReturnedDividends)); }
public IActionResult SaveDividends(string symbol) { List <Dividend> dividends = GetDividends(symbol); // save the quote if the quote has not already been saved in the database foreach (Dividend dividend in dividends) { //Database will give PK constraint violation error when trying to insert record with existing PK. if (dbContext.Dividends.Where(c => c.DividendId.Equals(dividend.DividendId)).Count() == 0) { dbContext.Dividends.Add(dividend); } } // persist the data dbContext.SaveChanges(); // populate the models to render in the view ViewBag.dbSuccessChart = 1; DividendVM diviendViewModel = getDividendVM(dividends); return(View("Dividend", diviendViewModel)); }