Esempio n. 1
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;
            }
        }
Esempio n. 2
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;
            }
        }