public void AddStock(StockInputModel model)
        {
            var stock = model.AsStock();

            _fund.Add(stock);
            UpdateStocks();
        }
Example #2
0
        public IActionResult Index(StockInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // get the known stocks
            var wantedStocks = Service.GetCookieStocks(Request.Cookies["KnownStocks"]);

            // add it to the list
            if (!wantedStocks.Contains(model.TickerName))
            {
                wantedStocks.Add(model.TickerName);
            }

            // append the cookie
            Response.Cookies.Append("KnownStocks",
                                    JsonConvert.SerializeObject(wantedStocks),
                                    new Microsoft.AspNetCore.Http.CookieOptions()
            {
                Expires = DateTime.Now.AddDays(10)
            });

            // go back to get method
            return(RedirectToAction("Index"));
        }
 private void AddNewStock()
 {
     try
     {
         var inputModel = new StockInputModel(Price, Quantity, StockType);
         _addStockHelper.AddStock(inputModel);
     }
     catch (ModelValidationException mex)
     {
         // log it and rethrow, eventually getting across to the exception boundary that would generate a user-friendly exception
         // having it reach the user as a suitable dialog window explaining the problem
     }
     finally
     {
         Reset();
     }
 }
Example #4
0
        public void AsStockReturnsNewBondForBondType()
        {
            var sut = new StockInputModel("10,0", "10", "Bond");

            Assert.IsInstanceOf(typeof(Bond), sut.AsStock());
        }
Example #5
0
        public void AsStockReturnsNewBondForEquityType()
        {
            var sut = new StockInputModel("10,0", "10", "Equity");

            Assert.IsInstanceOf(typeof(Equity), sut.AsStock());
        }
Example #6
0
 public void AddStock(StockInputModel model)
 {
     _fundViewModel.AddStock(model);
     _summaryViewModel.Update();
 }