Ejemplo n.º 1
0
        public ActionResult Add(Stock stock)
        {
            if (ModelState.IsValid)
            {
                _Repositoire.AddStock(stock);
                return RedirectToAction("Index");
            }

            return View(stock);
        }
Ejemplo n.º 2
0
        public ActionResult Add(int id = 0)
        {
            var stock = new Stock();

            if (id != 0)
            {
                stock = _Repositoire.GetStock(id);
            }

            return View(stock);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 public void Scrape(Stock stock)
 {
     var lastKnownPrice = FinanceRepositoire.LastKnownPrice(stock.StockId);
     var newPrices = GetLatestStock(stock, lastKnownPrice, DateTime.Today.Date);
     FinanceRepositoire.SavePrices(stock.StockId, newPrices);
 }
Ejemplo n.º 7
0
 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;
        }
Ejemplo n.º 9
0
 public void UpdateData(Stock stock)
 {
     //Every type should only have one scraper
     Scrapers.Single(scraper => scraper.ScraperType == stock.ScraperType).Scrape(stock);
 }