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();
 }
        public IEnumerable<string> getKnownIdentifiers(ApplicationDbContext db, ApplicationUser user)
        {
            var transactions = this.getTransactions(db, user);
            var ids = transactions.Select(x => x.StockTicker).Distinct().ToList();

            var idPrice = ids.Select(x => Tuple.Create(x, transactions.Where(y => y.StockTicker.Equals(x)).Select(y => y.TotalPrice).Sum()));

            return idPrice.OrderBy(x => x.Item2).Select(x => x.Item1).Take(6);
        }
        public async Task<Stock> getNote(ApplicationDbContext db, ApplicationUser user, Stock stock) {
            if (stock.Identifier == "F")
            {
                stock.Note = "Ford Motor Comp";
            }
            if (stock.Identifier == "TWTR")
            {
                stock.Note = "Who needs 140 characters?";
            }

            return stock;
        }
        public async Task setNote(ApplicationDbContext db, ApplicationUser user, Stock stock)
        {
            var note = db.StockNotes.Where(x => (x.UserId.Equals(user.Id)) && (x.StockTicker.Equals(stock.Identifier)));

            if (note.Count() == 0)
            {
                var newNote = new StockNote();
                newNote.Note = stock.Note;
                newNote.StockTicker = stock.Identifier;
                newNote.UserId = user.Id;

                db.StockNotes.Add(newNote);
            }
            else
            {
                var a = note.First();
                db.StockNotes.Update(a);
                a.Note = stock.Note;
            }
            db.SaveChanges();
        }
 public Task setNote(ApplicationDbContext db, ApplicationUser user, Stock stock)
 {
     if (wasCalled) { throw new Exception("SetNote called twice"); }
     this.wasCalled = true;
     this.Note = stock.Note;
     this.Symbol = stock.Identifier;
     return new Task(() => { });
 }
 public Task<Stock> getNote(ApplicationDbContext db, ApplicationUser user, Stock stock)
 {
     stock.Note = this.Note;
     return new Task<Stock>(() => stock);
 }
 public IEnumerable<StockTransaction> getTransactions(ApplicationDbContext db, ApplicationUser user, string identifier)
 {
     return this.transactions().FindAll(x => x.Key == identifier).Select(x => x.Value);
 }
 public IEnumerable<string> getKnownIdentifiers(ApplicationDbContext db, ApplicationUser user)
 {
     return this.transactions().Select(x => x.Key).Distinct();
 }
 public void clear(ApplicationDbContext db, ApplicationUser user)
 {
 }
 public void addTransaction(ApplicationDbContext db, ApplicationUser user, Stock stock, StockTransaction model)
 {
 }
 public IEnumerable<StockTransaction> getTransactions(ApplicationDbContext db, ApplicationUser user, string tickerSymbol)
 {
     return db.StockTransactions.Where(x => x.StockTicker.Equals(tickerSymbol) && x.UserId.Equals(user.Id));
 }
 public IEnumerable<StockTransaction> getTransactions(ApplicationDbContext db, ApplicationUser user)
 {
     return db.StockTransactions.Where(x => x.UserId.Equals(user.Id));
 }
 public void clear(ApplicationDbContext db, ApplicationUser user)
 {
     var elemsToRemove = db.StockTransactions.Where(x => x.UserId.Equals(user.Id));
     elemsToRemove.ToList().ForEach(x => db.StockTransactions.Remove(x));
     db.SaveChanges();
 }
        public IEnumerable<StockTransaction> getTransactions(ApplicationDbContext db, ApplicationUser user)
        {
            var retVal = transactions();
            retVal.ForEach(x => x.Value.StockTicker = x.Key);

            return retVal.Select(x => x.Value);
        }
 public async Task<Stock> getNote(ApplicationDbContext db, ApplicationUser user, Stock stock) {
     string result = db.StockNotes.Where(x => (x.UserId.Equals(user.Id)) && (x.StockTicker == stock.Identifier)).Select(x => x.Note).FirstOrDefault();
     
     stock.Note = result;
     return stock;
 }
 public async Task setNote(ApplicationDbContext db, ApplicationUser user, Stock stock) {
     System.Diagnostics.Debug.WriteLine(stock.Identifier + ": " + stock.Note);
 }