public ActionResult Lab5(Lab5ViewModel model) { string chartSrc = string.Format("http://ichart.finance.yahoo.com/{0}={1}", "b?s", model.StockSymbol); string url = string.Format("http://finance.yahoo.com/q/cp?s={0}&ql=1", model.StockSymbol); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Method = "GET"; httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); //httpWebRequest.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string response = streamReader.ReadToEnd(); string start = @"<div class=""rtq_leaf"">"; string end = @"<div id=""yfi_toolbox_mini_rtq"">"; int startIndex = response.IndexOf(start); int endIndex = response.IndexOf(end); if(startIndex > 0 && endIndex > 0 && (endIndex > startIndex)) { string stockSummaryHTML = response.Substring(startIndex, endIndex - startIndex); stockSummaryHTML = stockSummaryHTML + @"</div></div></div></div>"; model.StockSummary = stockSummaryHTML; model.StockChart = chartSrc; model.LastUpdated = DateTime.Now; //Save the information Lab5DataAccess dataAccess = new Lab5DataAccess(RavenSession); Lab5ViewModel lab5Model = dataAccess.RetrieveFromSession(); lab5Model.InjectFrom(model); } else { using(StringWriter sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "_StockSummaryPartial"); ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); model.StockSummary = sw.GetStringBuilder().ToString(); } } return View("Lab5", model); }
// // POST: /Labs/Lab5 public ActionResult Lab5() { Lab5DataAccess dataAccess = new Lab5DataAccess(RavenSession); Lab5ViewModel model = dataAccess.RetrieveFromSession(); return View("Lab5", model); }