public void addTransaction(ApplicationDbContext db, ApplicationUser user, Stock stock, StockTransaction model)
 {
     model.StockTicker = stock.Identifier;
     model.UserId = user.Id;
     db.StockTransactions.Add(model);
     db.SaveChanges();
 }
예제 #2
0
 public StockTest()
 {
     _stock = new Stock("MSFT");
     _stock.CurrentPrice = 5.5m;
     _purchase1 = new StockTransaction(DateTime.Now, 4.0m, 7);
     _purchase2 = new StockTransaction(DateTime.Now.AddDays(-1), 7.5m, 2);
     _sale1 = new StockTransaction(DateTime.Now, 5.0m, -1);
 }
        public async Task<IActionResult> Buy(string symbol, int shares)
        {
            var stock = new Stock(symbol);
            stock = await stockInfo.GetQuoteAsync(stock);

            var model = new StockTransaction(DateTime.Now, stock.CurrentPrice.Value, shares);
            stockHistory.addTransaction(_applicationDbContext, await GetCurrentUserAsync(), stock, model);

            return Redirect("/Stocks/SearchStocks?symbol=" + symbol);
        }
 public void TotalPriceShouldEqualSharesTimesPrice()
 {
     var trans = new StockTransaction(DateTime.Now, 2.5m, 2);
     Assert.Equal(5.0m, trans.TotalPrice);
 }
 public void addTransaction(ApplicationDbContext db, ApplicationUser user, Stock stock, StockTransaction model)
 {
 }
        public async Task<IActionResult> LoadHistory(System.Web.HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var reader = new Microsoft.VisualBasic.FileIO.TextFieldParser(file.InputStream);
                reader.SetDelimiters(",");
                while (!reader.EndOfData)
                {
                    var line = reader.ReadFields();

                    var stock = new Stock(line[0]);
                    var model = new StockTransaction(DateTime.Parse(line[1]), Decimal.Parse(line[2]), int.Parse(line[3]));
                    stockHistory.addTransaction(_applicationDbContext, await GetCurrentUserAsync(), stock, model);
                }
            }

            return Redirect("/Stocks/History");
        }