Ejemplo n.º 1
0
        public decimal GetPrice(string tickers)
        {
            decimal price = 0;
            string  json;

            try
            {
                //remove white space for api
                tickers = tickers.Replace(" ", "");

                using (var web = new WebClient())
                {
                    var url = $"https://api.iextrading.com/1.0/stock/{tickers}/quote";
                    json = web.DownloadString(url);
                }

                //json = json.Replace("\\", "");

                JObject v = JObject.Parse(json);

                var ticker = v.SelectToken("symbol");
                price = (decimal)v.SelectToken("delayedPrice");
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
            return(price);
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        public double GetPrice(string symbols)
        {
            double price = 0;
            string json;

            //remove white space for api
            symbols = symbols.Replace(" ", "");

            try
            {
                using (var web = new WebClient())
                {
                    var url = $"https://api.coinmarketcap.com/v1/ticker/{symbols}/";
                    json = web.DownloadString(url);
                }

                //json = json.Replace("\\", "");

                JArray v = JArray.Parse(json);

                foreach (var a in v)
                {
                    var symbol = a.SelectToken("id");
                    price = (double)a.SelectToken("price_usd");
                }
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
            price = Math.Round(price, 2);
            return(price);
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
        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;
            }
        }
Ejemplo n.º 9
0
        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;
            }
        }
Ejemplo n.º 10
0
        public decimal GetTotalShares(string ticker)
        {
            int total = 0;

            try
            {
                CTransaction t = new CTransaction();
                total = t.GetTotalShares(ticker);
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
            return(total);
        }
Ejemplo n.º 11
0
        public decimal GetTotalShares(string symbol)
        {
            decimal total = 0;

            try
            {
                CCryptoTran t = new CCryptoTran();
                total = t.GetTotalShares(symbol);
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
            return(total);
        }
Ejemplo n.º 12
0
        public double GetTotalPerTick(string symbol)
        {
            double total = 0;

            try
            {
                CCryptoTran t = new CCryptoTran();
                total = t.GetTotal(symbol);
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
            return(total);
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        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;
            }
        }
Ejemplo n.º 15
0
        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;
            }
        }
Ejemplo n.º 16
0
        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;
            }
        }
Ejemplo n.º 17
0
        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;
            }
        }
Ejemplo n.º 18
0
        public void SendEmail()
        {
            try
            {
                string      to      = "*****@*****.**";
                string      from    = "*****@*****.**";
                string      subject = "Do Not Reply - Wealth Manager Notification";
                string      body    = @"You have ner transactions to view!";
                MailMessage message = new MailMessage(from, to, subject, body);
                System.Net.NetworkCredential auth = new System.Net.NetworkCredential("*****@*****.**", "aorvlycgeupwksmn");
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.Timeout = 100000;
                // Credentials are necessary if the server requires the client
                // to authenticate before it will send e-mail on the client's behalf.
                client.Credentials           = CredentialCache.DefaultNetworkCredentials;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = false;
                message.IsBodyHtml           = true;
                client.Credentials           = auth;

                client.Send(message);



                //    MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**", "New Transaction!", "You added a new transaction!");
                //System.Net.NetworkCredential auth = new System.Net.NetworkCredential("*****@*****.**", "");
                //SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                //client.EnableSsl = false;
                //client.UseDefaultCredentials = false;
                //mail.IsBodyHtml = true;
                //client.Credentials = auth;
                //client.Send(mail);
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw;
            }
        }
Ejemplo n.º 19
0
        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;
            }
        }
Ejemplo n.º 20
0
        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;
            }
        }
Ejemplo n.º 21
0
        public void Insert()
        {
            WealthDataContext oDc = new WealthDataContext();

            try
            {
                var results = (from s in oDc.tblStocks
                               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.Ticker,
                    s.CurrentPricePerShare,
                }).FirstOrDefault();



                if (results == null)
                {
                    tblStock stock = new tblStock();

                    stock.Id     = Guid.NewGuid();
                    stock.UserId = CLogin.UserLoggedIn;
                    stock.Ticker = this.Ticker.ToUpper();
                    stock.CurrentPricePerShare = GetPrice(this.Ticker);
                    oDc.tblStocks.InsertOnSubmit(stock);
                    oDc.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 22
0
        public void LoadById()
        {
            try
            {
                WealthDataContext oDc  = new WealthDataContext();
                tblUser           user = oDc.tblUsers.FirstOrDefault(p => p.Id == this.Id);

                if (user != null)
                {
                    this.Id        = user.Id;
                    this.FirstName = user.FirstName;
                    this.LastName  = user.LastName;
                    this.Email     = user.Email;
                    user.Password  = user.Password;
                }
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 23
0
        public void Export()
        {
            try
            {
                int iCnt = 0;

                Load();
                //TODO: figure out why this.count is = to 0. it should be = to 2

                string[,] transactions = new string[this.Count + 1, 6];

                transactions[0, 0] = "Ticker";
                transactions[0, 1] = "Transaction Date";
                transactions[0, 2] = "Quantity";
                transactions[0, 3] = "Price";
                transactions[0, 4] = "Buy";

                while (iCnt < this.Count)
                {
                    iCnt++;
                    CTransaction v = this[iCnt - 1];
                    transactions[iCnt, 0] = v.Ticker.ToString();
                    transactions[iCnt, 1] = v.TransDate.ToString();
                    transactions[iCnt, 2] = v.Quantity.ToString();
                    transactions[iCnt, 3] = v.PricePerSharePaid.ToString();
                    transactions[iCnt, 4] = v.Buy.ToString();
                }

                CExcel.Export("Transaction.xlsx", transactions);
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 24
0
        public void Insert()
        {
            try
            {
                WealthDataContext oDc  = new WealthDataContext();
                tblUser           user = new tblUser
                {
                    FirstName = this.FirstName,
                    LastName  = this.LastName,
                    Email     = this.Email,
                    Password  = this.GetHash(),
                    Id        = Guid.NewGuid()
                };

                oDc.tblUsers.InsertOnSubmit(user);
                oDc.SubmitChanges();
            }
            catch (Exception ex)
            {
                CErrorLog err = new CErrorLog();
                err.LogError(ex.Message);
                throw ex;
            }
        }