コード例 #1
0
		private async Task AddTestHoldings(string userName)
		{
			if (!_context.Holdings.Any())
			{
				var afiHolding = new Holding()
				{
					Username = userName,
					Ticker = "AFI.AX",
					Trades = new List<Trade>()
					{
						new Trade() { TradeType = "Buy", Date = new DateTime(2013, 01, 01), Price = 5.2m, Quantity = 1000, Brokerage = 19.95m },
						new Trade() { TradeType = "Buy", Date = new DateTime(2014, 01, 01), Price = 5.8m, Quantity = 1000, Brokerage = 19.95m },
					}
				};

				_context.Holdings.Add(afiHolding);
				_context.Trades.AddRange(afiHolding.Trades);

				var annHolding = new Holding()
				{
					Username = userName,
					Ticker = "ANN.AX",
					Trades = new List<Trade>()
					{
						new Trade() { TradeType = "Buy", Date = new DateTime(2013, 01, 01), Price = 15.2m, Quantity = 1000, Brokerage = 19.95m },
						new Trade() { TradeType = "Buy", Date = new DateTime(2014, 01, 01), Price = 16.8m, Quantity = 1000, Brokerage = 19.95m },
					}
				};

				_context.Holdings.Add(annHolding);
				_context.Trades.AddRange(annHolding.Trades);

				await _context.SaveChangesAsync();
			}
		}
コード例 #2
0
		public IActionResult Create(Holding holding)
		{
			if (ModelState.IsValid)
			{
				holding.Username = User.Identity.Name;
				_repository.AddHolding(holding);
				_repository.SaveAll();
				return RedirectToAction("Index");
			}
			return View(holding);
		}
コード例 #3
0
		public IActionResult Edit(Holding holding)
		{
			if (ModelState.IsValid)
			{
				var existingHolding = _repository.GetHolding(holding.Id, User.Identity.Name);
				var holdingIsForLoggedInUser = existingHolding != null;
				if (!holdingIsForLoggedInUser)
				{
					return HttpNotFound();
				}

				existingHolding.Ticker = holding.Ticker;

				_repository.UpdateHolding(existingHolding);
				_repository.SaveAll();
				return RedirectToAction("Index");
			}
			return View(holding);
		}
コード例 #4
0
		public void RemoveHolding(Holding holding)
		{
			_context.Holdings.Remove(holding);
		}
コード例 #5
0
		public void UpdateHolding(Holding holding)
		{
			_context.Update(holding);
		}
コード例 #6
0
		public void AddHolding(Holding holding)
		{
			_context.Holdings.Add(holding);
		}