public void LoadById(Guid id) { try { WealthDataContext oDc = new WealthDataContext(); var result = (from t in oDc.tblTransactions join s in oDc.tblStocks on t.StockId equals s.Id where t.Id == id orderby t.TransDate select new { t.Id, quan = t.Quantity, tdate = t.TransDate, tbuy = t.Buy, tpps = t.PricePerSharePaid, }).FirstOrDefault(); this.Id = result.Id; this.Quantity = (int)result.quan; this.TransDate = (DateTime)result.tdate; this.Buy = (bool)result.tbuy; this.PricePerSharePaid = (decimal)result.tpps; } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void Update() { try { WealthDataContext oDc = new WealthDataContext(); tblUser user = oDc.tblUsers.FirstOrDefault(p => p.Id == this.Id); if (user != null) { user.FirstName = this.FirstName; user.LastName = this.LastName; user.Email = this.Email; user.Password = this.Password; oDc.SubmitChanges(); } else { throw new Exception("Row not found. (Id : " + this.Id + ")"); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void Update() { try { WealthDataContext oDc = new WealthDataContext(); tblTransaction transaction = oDc.tblTransactions.FirstOrDefault(p => p.Id == this.Id); if (transaction != null) { transaction.TransDate = this.TransDate; transaction.Buy = this.Buy; transaction.StockId = this.StockId; transaction.Quantity = this.Quantity; transaction.PricePerSharePaid = this.PricePerSharePaid; oDc.SubmitChanges(); } else { throw new Exception("Row not found. (Id : " + this.Id + ")"); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void Insert() { WealthDataContext oDc = new WealthDataContext(); tblCryptoTran transaction = new tblCryptoTran(); var result = (from s in oDc.tblCryptos join u in oDc.tblUsers on s.UserId equals u.Id where u.Id == CLogin.UserLoggedIn & s.Id == this.StockId select new { oldid = s.Id }).FirstOrDefault(); transaction.Id = Guid.NewGuid(); transaction.CryptoId = result.oldid; transaction.TransDate = this.TransDate; transaction.Buy = this.Buy; transaction.Quantity = this.Quantity; decimal g; decimal.TryParse(this.PricePerSharePaid.ToString(), out g); transaction.Price = g; oDc.tblCryptoTrans.InsertOnSubmit(transaction); oDc.SubmitChanges(); }
public void Update() { try { WealthDataContext oDc = new WealthDataContext(); tblCrypto stock = oDc.tblCryptos.FirstOrDefault(p => p.Id == this.Id); if (stock != null) { stock.Symbol = this.Ticker; decimal.TryParse(GetPrice(this.Ticker).ToString(), out decimal g); stock.CurrentPrice = g; stock.UserId = this.UserId; oDc.SubmitChanges(); } else { throw new Exception("Row not found. (Id : " + this.Id + ")"); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void LoadTest() { WealthDataContext wdc = new WealthDataContext(); List <tblTransaction> trans = (from u in wdc.tblTransactions select u).ToList(); Assert.AreNotEqual(0, trans.Count); }
public void LoadTest() { WealthDataContext wdc = new WealthDataContext(); List <tblUser> users = (from u in wdc.tblUsers select u).ToList(); Assert.AreNotEqual(0, users.Count); }
public void LoadTest() { WealthDataContext wdc = new WealthDataContext(); List <tblStock> stocks = (from u in wdc.tblStocks select u).ToList(); Assert.AreNotEqual(0, stocks.Count); }
public bool Login(string userId, string userPass) { Email = userId; Password = userPass; try { if (Email != string.Empty && Password != string.Empty) { WealthDataContext oDc = new WealthDataContext(); tblUser user = oDc.tblUsers.FirstOrDefault(p => p.Email == this.Email); if (user != null) { tblUser user2 = oDc.tblUsers.FirstOrDefault(p => p.Password == this.GetHash()); if (user2 != null) { FirstName = user.FirstName; LastName = user.LastName; Password = user.Password; Email = user.Email; Id = user.Id; //set the app to the user CLogin.set(Id); return(true); } else { oDc = null; throw new Exception("Credentials are incorrect"); } } else { oDc = null; throw new Exception("User ID: " + Email + " could not be found"); } } else { throw new Exception("User ID and Password cannok be blank. Try again"); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void DeleteTest() { WealthDataContext wdc = new WealthDataContext(); tblStock stocks = (from u in wdc.tblStocks where u.Ticker == "VEU" select u).FirstOrDefault(); wdc.tblStocks.DeleteOnSubmit(stocks); wdc.SubmitChanges(); tblStock stockDelete = (from u in wdc.tblStocks where u.Ticker == "VEU" select u).FirstOrDefault(); Assert.IsNull(stockDelete); }
public void DeleteTest() { WealthDataContext wdc = new WealthDataContext(); tblUser users = (from u in wdc.tblUsers where u.Password == "TestPassword" select u).FirstOrDefault(); wdc.tblUsers.DeleteOnSubmit(users); wdc.SubmitChanges(); tblUser userDelete = (from u in wdc.tblUsers where u.Password == "TestPassword" select u).FirstOrDefault(); Assert.IsNull(userDelete); }
public void DeleteTest() { WealthDataContext wdc = new WealthDataContext(); tblTransaction trans = (from u in wdc.tblTransactions where u.Quantity == 50 select u).FirstOrDefault(); wdc.tblTransactions.DeleteOnSubmit(trans); wdc.SubmitChanges(); tblTransaction transDelete = (from u in wdc.tblTransactions where u.Quantity == 50 select u).FirstOrDefault(); Assert.IsNull(transDelete); }
public void UpdateTest() { WealthDataContext wdc = new WealthDataContext(); tblStock stocks = (from u in wdc.tblStocks where u.Ticker == "VTI" select u).FirstOrDefault(); stocks.Ticker = "VEU"; wdc.SubmitChanges(); tblStock stockUpdate = (from u in wdc.tblStocks where u.Ticker == "VEU" select u).FirstOrDefault(); Assert.IsNotNull(stockUpdate); }
public void UpdateTest() { WealthDataContext wdc = new WealthDataContext(); tblTransaction trans = (from u in wdc.tblTransactions where u.PricePerSharePaid == 336 select u).FirstOrDefault(); trans.Quantity = 50; wdc.SubmitChanges(); tblTransaction transUpdate = (from u in wdc.tblTransactions where u.Quantity == 50 select u).FirstOrDefault(); Assert.IsNotNull(transUpdate); }
public void UpdateTest() { WealthDataContext wdc = new WealthDataContext(); tblUser users = (from u in wdc.tblUsers where u.Password == "TestPassword" select u).FirstOrDefault(); users.FirstName = "NewFirstNameTest"; wdc.SubmitChanges(); tblUser userUpdate = (from u in wdc.tblUsers where u.FirstName == "NewFirstNameTest" select u).FirstOrDefault(); Assert.IsNotNull(userUpdate); }
public bool Login() { try { if (Email != string.Empty && Password != string.Empty) { WealthDataContext oDc = new WealthDataContext(); tblUser otblUser = oDc.tblUsers.FirstOrDefault(u => u.Email == Email); if (otblUser != null) { tblUser ouser = oDc.tblUsers.FirstOrDefault(u => u.Password == GetHash()); if (ouser != null) { FirstName = ouser.FirstName; LastName = ouser.LastName; Password = ouser.Password; Email = ouser.Email; Id = ouser.Id; //set the app to the user CLogin.set(Id); return(true); } else { oDc = null; throw new Exception("Password is incorrect"); } } else { oDc = null; throw new Exception("Email: " + Email + " could not be found"); } } else { throw new Exception("User ID and Password cannok be blank. Try again"); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void LoadById(Guid id) { WealthDataContext oDc = new WealthDataContext(); tblCrypto stock = oDc.tblCryptos.FirstOrDefault(p => p.Id == Id); if (stock != null) { this.Id = stock.Id; } this.Price = GetPrice(this.Ticker); if (stock != null) { this.Ticker = stock.Symbol; } }
public double GetTotal(string ticker) { try { CCrypto stock = new CCrypto(); decimal totalQuan = 0; double tickerprice = 0; WealthDataContext oDc = new WealthDataContext(); var results = (from u in oDc.tblUsers join s in oDc.tblCryptos on u.Id equals s.UserId join t in oDc.tblCryptoTrans on s.Id equals t.CryptoId where s.Symbol == ticker && s.UserId == CLogin.UserLoggedIn select new { quan = t.Quantity, buy = t.Buy }).ToList(); foreach (var quan in results) { if (quan.buy == true) { this.Quantity = (decimal)quan.quan; totalQuan = Quantity += totalQuan; } else { this.Quantity = (decimal)quan.quan; totalQuan = totalQuan -= Quantity; } } tickerprice = stock.GetPrice(ticker); double.TryParse(totalQuan.ToString(), out double g); double temp; temp = g * tickerprice; temp = Math.Round(temp, 2); return(temp); } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void Insert() { try { WealthDataContext oDc = new WealthDataContext(); var results = (from s in oDc.tblCryptos join u in oDc.tblUsers on s.UserId equals u.Id where u.Id == CLogin.UserLoggedIn & s.Id == this.Id select new { s.Id, custId = s.UserId, s.Symbol, s.CurrentPrice, }).ToList(); if (results != null) { //WealthDataContext oDc = new WealthDataContext(); tblCrypto stock = new tblCrypto(); stock.Id = Guid.NewGuid(); stock.UserId = CLogin.UserLoggedIn; stock.Symbol = this.Ticker; decimal.TryParse(GetPrice(this.Ticker).ToString(), out decimal g); stock.CurrentPrice = g; oDc.tblCryptos.InsertOnSubmit(stock); oDc.SubmitChanges(); } else { } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void InsertTest() { WealthDataContext wdc = new WealthDataContext(); tblStock otblstock = new tblStock(); otblstock.Id = Guid.NewGuid(); otblstock.UserId = Guid.NewGuid(); otblstock.Ticker = "VTI"; wdc.tblStocks.InsertOnSubmit(otblstock); wdc.SubmitChanges(); tblStock stocks = (from u in wdc.tblStocks where u.Ticker == "VTI" select u).FirstOrDefault(); Assert.IsNotNull(stocks); }
public decimal GetTotal(string ticker) { try { CStock stock = new CStock(); int totalQuan = 0; decimal tickerprice = 0; WealthDataContext oDc = new WealthDataContext(); var results = (from u in oDc.tblUsers join s in oDc.tblStocks on u.Id equals s.UserId join t in oDc.tblTransactions on s.Id equals t.StockId where s.Ticker == ticker && s.UserId == CLogin.UserLoggedIn select new { quan = t.Quantity, buy = t.Buy }).ToList(); foreach (var quan in results) { if (quan.buy == true) { this.Quantity = (int)quan.quan; totalQuan = Quantity += totalQuan; } else { this.Quantity = (int)quan.quan; totalQuan = totalQuan -= Quantity; } } tickerprice = stock.GetPrice(ticker); return(totalQuan * tickerprice); } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void Load() { try { WealthDataContext oDc = new WealthDataContext(); var result = (from t in oDc.tblTransactions join s in oDc.tblStocks on t.StockId equals s.Id join u in oDc.tblUsers on s.UserId equals u.Id where u.Id == CLogin.UserLoggedIn orderby t.TransDate select new { t.Id, t.StockId, quan = t.Quantity, tdate = t.TransDate, tbuy = t.Buy, tpps = t.PricePerSharePaid, tick = s.Ticker }).ToList(); foreach (var tran in result) { CTransaction oTran = new CTransaction(); oTran.Ticker = tran.tick; oTran.Id = tran.Id; oTran.StockId = (Guid)tran.StockId; oTran.Quantity = (int)tran.quan; oTran.TransDate = (DateTime)tran.tdate; oTran.Buy = (bool)tran.tbuy; oTran.PricePerSharePaid = (decimal)tran.tpps; Add(oTran); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public Guid GetGuid(string stocktick) { Guid newguid; WealthDataContext oDc = new WealthDataContext(); var result = (from s in oDc.tblStocks where s.Ticker == stocktick select new { sid = s.Id }).FirstOrDefault(); newguid = result.sid; return(newguid); }
public void InsertTest() { WealthDataContext wdc = new WealthDataContext(); tblUser otbluser = new tblUser(); otbluser.Id = Guid.NewGuid(); otbluser.FirstName = "Test"; otbluser.LastName = "Test"; otbluser.Email = "*****@*****.**"; otbluser.Password = "******"; wdc.tblUsers.InsertOnSubmit(otbluser); wdc.SubmitChanges(); tblUser users = (from u in wdc.tblUsers where u.Password == "TestPassword" select u).FirstOrDefault(); Assert.IsNotNull(users); }
public void LogError(string message) { try { WealthDataContext oDc = new WealthDataContext(); tblErrorLog err = new tblErrorLog(); err.Id = Guid.NewGuid(); err.Message = message; err.DateTime = DateTime.Now; oDc.tblErrorLogs.InsertOnSubmit(err); oDc.SubmitChanges(); } catch (Exception ex) { throw ex; } }
public void Delete() { try { WealthDataContext oDc = new WealthDataContext(); tblTransaction transaction = oDc.tblTransactions.FirstOrDefault(p => p.Id == this.Id); if (transaction != null) { oDc.tblTransactions.DeleteOnSubmit(transaction); oDc.SubmitChanges(); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void InsertTest() { WealthDataContext wdc = new WealthDataContext(); tblTransaction otblTrans = new tblTransaction(); otblTrans.Id = Guid.NewGuid(); otblTrans.TransDate = DateTime.Now; otblTrans.Buy = true; otblTrans.Quantity = 100; otblTrans.PricePerSharePaid = 336; otblTrans.StockId = Guid.NewGuid(); wdc.tblTransactions.InsertOnSubmit(otblTrans); wdc.SubmitChanges(); tblTransaction trans = (from u in wdc.tblTransactions where u.PricePerSharePaid == 336 select u).FirstOrDefault(); Assert.IsNotNull(trans); }
public decimal GetTotalShares(string ticker) { try { CCrypto stock = new CCrypto(); decimal totalQuan = 0; WealthDataContext oDc = new WealthDataContext(); var results = (from u in oDc.tblUsers join s in oDc.tblCryptos on u.Id equals s.UserId join t in oDc.tblCryptoTrans on s.Id equals t.CryptoId where s.Symbol == ticker && s.UserId == CLogin.UserLoggedIn select new { quan = t.Quantity, buy = t.Buy }).ToList(); foreach (var quan in results) { if (quan.buy == true) { this.Quantity = (decimal)quan.quan; totalQuan = Quantity += totalQuan; } else { this.Quantity = (decimal)quan.quan; totalQuan = totalQuan -= Quantity; } } return(totalQuan); } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void Load() { try { //we will need to pass in the userID here to be able to limit the user to only see their list of stocks. see below * WealthDataContext oDc = new WealthDataContext(); var results = (from s in oDc.tblStocks join u in oDc.tblUsers on s.UserId equals u.Id where u.Id == CLogin.UserLoggedIn orderby s.Ticker // * where s.userid == u.userId select new { s.Id, custId = s.UserId, s.Ticker, s.CurrentPricePerShare, }).ToList(); foreach (var stock in results) { CStock oStock = new CStock(); CTransaction t = new CTransaction(); oStock.TotalPerTick = t.GetTotal(stock.Ticker); oStock.TotalShares = t.GetTotalShares(stock.Ticker); oStock.Id = stock.Id; oStock.Ticker = stock.Ticker; oStock.Price = GetPrice(stock.Ticker); Add(oStock); } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
public void LoadById(Guid id) { try { WealthDataContext oDc = new WealthDataContext(); tblStock stock = oDc.tblStocks.FirstOrDefault(p => p.Id == id); if (stock != null) { this.Id = id; this.Ticker = stock.Ticker; this.Price = GetPrice(this.Ticker); //this.UserId = stock.UserId; } } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }