public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); StockNamesModel data = JsonConvert.DeserializeObject <StockNamesModel>(requestBody); if (data.stockNames == null || data.stockNames.Count <= 0) { return(new BadRequestResult()); } var connectionString = "DefaultEndpointsProtocol=https;AccountName=storageaccount4471b6a6;AccountKey=dX2VUCuxC0EcRnyZ7Srg+XIKLLagAO30kkpcBcsv9bq91rG+h2FomX6EHP/IByNzKSxVdRIqq6phUYDQ3PAPnw==;EndpointSuffix=core.windows.net"; Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("stocksinfo"); var comparisonList = new StockComparisonInfo(); foreach (var s in data.stockNames) { var info = StockSummary.GetSummary(table, s); comparisonList.StockSummaries.Add(info); } return(new OkObjectResult(JsonConvert.SerializeObject(comparisonList))); }
public async Task <IActionResult> CreateOne(IFormCollection formCollection) { //TODO should be in a list but too lazy ViewBag.UsrStockname1 = formCollection["nameOfStockOne"]; ViewBag.UsrStockname2 = formCollection["nameOfStockTwo"]; ViewBag.UsrStockname3 = formCollection["nameOfStockThree"]; ViewBag.UsrStockname4 = formCollection["nameOfStockFour"]; ViewBag.UsrStockname5 = formCollection["nameOfStockFive"]; var msg = new StockNamesModel(); msg.stockNames = new List <string>(); if (!string.IsNullOrWhiteSpace(formCollection["nameOfStockOne"].ToString())) { msg.stockNames.Add(formCollection["nameOfStockOne"].ToString()); } if (!string.IsNullOrWhiteSpace(formCollection["nameOfStockTwo"].ToString())) { msg.stockNames.Add(formCollection["nameOfStockTwo"].ToString()); } if (!string.IsNullOrWhiteSpace(formCollection["nameOfStockThree"].ToString())) { msg.stockNames.Add(formCollection["nameOfStockThree"].ToString()); } if (!string.IsNullOrWhiteSpace(formCollection["nameOfStockFour"].ToString())) { msg.stockNames.Add(formCollection["nameOfStockFour"].ToString()); } if (!string.IsNullOrWhiteSpace(formCollection["nameOfStockFive"].ToString())) { msg.stockNames.Add(formCollection["nameOfStockFive"].ToString()); } var content = new StringContent(JsonConvert.SerializeObject(msg), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://cs4471-stocksummaryandcomparisonservice.azurewebsites.net/api/StockComparison", content); response.EnsureSuccessStatusCode(); var stockSummaries = JsonConvert.DeserializeObject <StockComparisonInfo>(response.Content.ReadAsStringAsync().Result); //this view bag should a array/list but im lazy so whatever if (stockSummaries.StockSummaries.Count >= 1) { foreach (StockSummaryInfo element in stockSummaries.StockSummaries) { if (element?.StockName != null) { if (string.Compare(element.StockName, formCollection["nameOfStockOne"].ToString()) == 0) { ViewBag.Usrfiftylow1 = element.low; ViewBag.Usrfiftyhigh1 = element.high; ViewBag.UsrmarketCap1 = element.marketCap; ViewBag.UsrpriceEarnRatio1 = element.priceToEarnRatio; } } } } if (stockSummaries.StockSummaries.Count >= 2) { foreach (StockSummaryInfo element in stockSummaries.StockSummaries) { if (element != null && element.StockName != null) { if (string.Compare(element.StockName, formCollection["nameOfStockTwo"].ToString()) == 0) { ViewBag.Usrfiftylow2 = element.low; ViewBag.Usrfiftyhigh2 = element.high; ViewBag.UsrmarketCap2 = element.marketCap; ViewBag.UsrpriceEarnRatio2 = element.priceToEarnRatio; } } } } if (stockSummaries.StockSummaries.Count >= 3) { foreach (StockSummaryInfo element in stockSummaries.StockSummaries) { if (element != null && element.StockName != null) { if (string.Compare(element.StockName, formCollection["nameOfStockThree"].ToString()) == 0) { ViewBag.Usrfiftylow3 = element.low; ViewBag.Usrfiftyhigh3 = element.high; ViewBag.UsrmarketCap3 = element.marketCap; ViewBag.UsrpriceEarnRatio3 = element.priceToEarnRatio; } } } } if (stockSummaries.StockSummaries.Count >= 4) { foreach (StockSummaryInfo element in stockSummaries.StockSummaries) { if (element != null && element.StockName != null) { if (string.Compare(element.StockName, formCollection["nameOfStockFour"].ToString()) == 0) { ViewBag.Usrfiftylow4 = element.low; ViewBag.Usrfiftyhigh4 = element.high; ViewBag.UsrmarketCap4 = element.marketCap; ViewBag.UsrpriceEarnRatio4 = element.priceToEarnRatio; } } } } if (stockSummaries.StockSummaries.Count >= 5) { foreach (StockSummaryInfo element in stockSummaries.StockSummaries) { if (element != null && element.StockName != null) { if (string.Compare(element.StockName, formCollection["nameOfStockFive"].ToString()) == 0) { ViewBag.Usrfiftylow5 = element.low; ViewBag.Usrfiftyhigh5 = element.high; ViewBag.UsrmarketCap5 = element.marketCap; ViewBag.UsrpriceEarnRatio5 = element.priceToEarnRatio; } } } } return(View()); }