public ActionResult Add(Stock stock) { if (ModelState.IsValid) { _Repositoire.AddStock(stock); return RedirectToAction("Index"); } return View(stock); }
public ActionResult Add(int id = 0) { var stock = new Stock(); if (id != 0) { stock = _Repositoire.GetStock(id); } return View(stock); }
public override IEnumerable<StockPrice> GetLatestStock(Stock stock, DateTime lastKnownPrice, DateTime today) { var returnValue = new List<StockPrice>(); var date = lastKnownPrice.AddDays(1); while ( date <= today) { returnValue.Add(GetPrice(stock, date)); date = date.AddDays(1); } return returnValue.Where(stockPrice => stockPrice != null).ToList(); }
public void AddStock(Stock stock) { //Add stock if (stock.StockId == 0) { _Context.AllStock.Add(stock); } else { _Context.AllStock.Attach(stock); _Context.Entry(stock).State = EntityState.Modified; } //TODO: What if stock prices has changed ? _Context.SaveChanges(); }
private StockPrice GetPrice(Stock stock, DateTime date) { StockPrice returnValue = null; var datum = date.ToString("yyyyMMdd"); var url = string.Format("http://www.tijd.be/ajax/historyDay?issueId={0}&date={1}", stock.ScraperMetaData1, datum); var pagina = Download(url); var pageResult = GetPageResult(pagina); if (pageResult.Date == datum) { returnValue = new StockPrice(); returnValue.Price = Double.Parse(pageResult.Price, CultureInfo.GetCultureInfo("BE")); returnValue.Time = date; } return returnValue; }
public void Scrape(Stock stock) { var lastKnownPrice = FinanceRepositoire.LastKnownPrice(stock.StockId); var newPrices = GetLatestStock(stock, lastKnownPrice, DateTime.Today.Date); FinanceRepositoire.SavePrices(stock.StockId, newPrices); }
public abstract IEnumerable<StockPrice> GetLatestStock(Stock stock, DateTime lastKnownPrice, DateTime today);
private Stock MakeStock() { //Make a stock item var stock = new Stock { Name = "Test stock", ISIN = "ABCD516168", ScraperType = ScraperType.DeTijd }; //Add Some random info stock.Prices.Add(new StockPrice { Price = 100.0, Time = DateTime.Today }); stock.Prices.Add(new StockPrice { Price = 95.0, Time = DateTime.Today.AddDays(-1) }); stock.Prices.Add(new StockPrice { Price = 80.0, Time = DateTime.Today.AddDays(-2) }); return stock; }
public void UpdateData(Stock stock) { //Every type should only have one scraper Scrapers.Single(scraper => scraper.ScraperType == stock.ScraperType).Scrape(stock); }