public Task Execute() { Cmd.WriteLine("Code (leave blank to cancel)"); var code = Cmd.Prompt(); if (string.IsNullOrEmpty(code)) { return SayWeAreCancelling(); } Cmd.WriteLine("Current price (leave blank to cancel)"); var priceValue = Cmd.Prompt(); decimal currentPrice; if (string.IsNullOrEmpty(priceValue)) { return SayWeAreCancelling(); } if (!decimal.TryParse(priceValue, out currentPrice)) { Cmd.WriteErrorLine("Price is invalid"); return SayWeAreCancelling(); } var security = new Security(code, currentPrice); _context.Securities.Add(security); _context.SaveChanges(); return Task.CompletedTask; }
public PortfolioItem AddItem(IDbContext context, Security security, decimal units) { var item = new PortfolioItem(this, security, units); context.PortfolioItems.Add(item); return item; }