public async Task <ActionResult <List <Chart> > > Post([FromBody] SamplingParameters query) { Dictionary <string, string> currencies = new Dictionary <string, string> { { "Доллар США", "R01235" }, { "Евро", "R01239" } }; Task[] tasks = new Task[2]; ValCurs valCurs1 = null; ValCurs valCurs2 = null; tasks[0] = Task.Factory.StartNew( () => valCurs1 = _requestToCbr .GetCurs(query.DateBegin, query.DateEnd, currencies["Доллар США"])); tasks[1] = Task.Factory.StartNew( () => valCurs2 = _requestToCbr .GetCurs(query.DateBegin, query.DateEnd, currencies["Евро"])); List <Chart> charts = new List <Chart>(); await Task.Factory.ContinueWhenAll(tasks, completedTasks => { var minVal = valCurs1.Record == null || valCurs2.Record == null ? "50" : valCurs1.Record.Concat(valCurs2.Record).Select(valCursRecord => valCursRecord.Value).Min(); charts.Add(_chartFactory.GetChart(valCurs1, minVal, currencies.ElementAt(0).Key)); charts.Add(_chartFactory.GetChart(valCurs2, minVal, currencies.ElementAt(1).Key)); }); return(new ObjectResult(charts)); }
public IActionResult Index(string stockSymbol) { if (!PriceRepository.CheckStockSymbolExists(stockSymbol)) { ViewBag.ErrorMessage = "Stock symbol not found!"; } else { DateTime start = new DateTime(2019, 1, 8); DateTime end = new DateTime(2019, 10, 10); Chart chart = ChartFactory.GetChart(stockSymbol, start, end, ChartType.Line, PriceType.Close); ViewBag.Labels = JsonConvert.SerializeObject(chart.XLabels); ViewBag.Data = JsonConvert.SerializeObject(chart.YValues); ViewBag.Title = chart.Title; ViewBag.YAxisLabel = "$"; } ViewBag.StockSymbol = stockSymbol.ToUpper(); return(View()); }