// GET: Stocks/Stocks // Returns "Stocks" partial view public ActionResult Stocks() { // Catch connection errors, redirect to another view if something went wrong var ownedStocks = GetUserOwnedStocks(); var siteOwnedStocks = GetSiteOwnedStocks(); var stockPrices = new StocksJsonData(); try { stockPrices = GetStockPrices(); } catch (WebException exception) { return(View("ConnectionError", new ResponseFormat() { Message = exception.ToString() })); } UpdateGraphData(stockPrices); var model = new StocksIndexViewModel { StockPrices = stockPrices.Items, PublicationDate = TimeZoneInfo.ConvertTime(stockPrices.PublicationDate, TimeZoneInfo.Local), AccountBalance = GetUserAccountBalance(), OwnedStocks = ownedStocks, StocksTableData = GenerateTableData(stockPrices.Items, ownedStocks, siteOwnedStocks), SiteOwnedStocks = siteOwnedStocks }; return(PartialView("Stocks", model)); }
public async System.Threading.Tasks.Task <ActionResult> Buy(string company, int amount) { var stockPrices = GetStockPrices(); var currentPrice = (decimal)Math.Round(stockPrices.Items.Single(p => p.Code == company).Price, 2); var result = await UpdateUserStocks(company, amount, currentPrice, true); var ownedStocks = GetUserOwnedStocks(); var siteOwnedStocks = GetSiteOwnedStocks(); var model = new StocksIndexViewModel { StockPrices = stockPrices.Items, PublicationDate = TimeZoneInfo.ConvertTime(stockPrices.PublicationDate, TimeZoneInfo.Local), Success = result.Success, Message = result.Message, AccountBalance = GetUserAccountBalance(), OwnedStocks = ownedStocks, StocksTableData = GenerateTableData(stockPrices.Items, ownedStocks, siteOwnedStocks), SiteOwnedStocks = siteOwnedStocks }; return(PartialView("Stocks", model)); }