Exemplo n.º 1
0
        private static void MapDtoToViewModel(BusinessLogic.Service.Contract.Dto.AmericanCenturyBuyDto dto, AmericanCenturyBuyViewModel viewModel)
        {
            //transactionViewModel.Amount = transactionDto.Amount;
            viewModel.AmountInvested = dto.Amount.ToString();
            //transactionViewModel.BhId = transactionDto.BhId.ToString();
            viewModel.BuyPrice = dto.Nav.ToString();
            //transactionViewModel.Company = transactionDto.Company;
            //transactionViewModel.Credit = transactionDto.DebitCredit;
            //transactionViewModel.DividendAmount = transactionDto.DividendAmount.ToString();
            //transactionViewModel.Fee = transactionDto.Fees;
            //transactionViewModel.Id = transactionDto.Id;
            //transactionViewModel.Notes = transactionDto.Notes;
            //transactionViewModel.NumShares = transactionDto.NumberShares.ToString();

            //transactionViewModel.Period = transactionDto.Period;
            viewModel.Shares = dto.Shares.ToString();
            //transactionViewModel.Symbol = transactionDto.Symbol;
            //transactionViewModel.SuspectedType = transactionDto.Transaction;
            viewModel.BuyDate = dto.Date.ToShortDateString();
            //transactionViewModel.TxId = transactionDto.TxId;
            //transactionViewModel.Type = transactionDto.Type;
            //transactionViewModel.Xref = transactionDto.Xref.ToString();
            //transactionViewModel.XXX = transactionDto.XXX;
        }
Exemplo n.º 2
0
        private List<AmericanCenturyBuyViewModel> GetTransactions(string ticker = "")
        {
            try
            {
                var totalShares = 0.0;
                var transactions = new List<AmericanCenturyBuyViewModel>();

                var transactionDtos = _americanCenturyService.GetTransactions();

                foreach (var transactionDto in transactionDtos)
                {
                    var transactionViewModel = new AmericanCenturyBuyViewModel();

                    MapDtoToViewModel(transactionDto, transactionViewModel);

                    double numShares = 0;
                    if (Double.TryParse(transactionDto.Shares.ToString(), out numShares))
                    {
                        totalShares += Math.Round(numShares, 4);
                        transactionViewModel.TotalShares = totalShares.ToString();
                    }
                    transactions.Add(transactionViewModel);
                }
                return transactions.OrderByDescending(p => p.BuyDate).ToList();

                //List<BuyAndHoldTransactionViewModel> buyAndHoldTransactions = new List<BuyAndHoldTransactionViewModel>();
                //connectionString = "Data Source=192.168.1.101;Initial Catalog=Invest;Persist Security Info=True;User ID=;Password=;";

                //if (ticker == "zzz")
                //{
                //    sql = "SELECT TOP 500 * FROM BuyAndHoldTransaction";
                //    sql += " WHERE ISNULL(XXX, '') != 'xxx'";
                //    sql += " ORDER BY TransactionDate DESC";
                //}

                //else if (!string.IsNullOrWhiteSpace(ticker))
                //{
                //    sql = "SELECT * FROM BuyAndHoldTransaction";
                //    sql += " WHERE Symbol = '" + ticker + "'";
                //    sql += " ORDER BY TransactionDate ";
                //}
                //else
                //{
                //    sql = "SELECT TOP 500 * FROM BuyAndHoldTransaction";
                //    sql += " WHERE ISNULL(XXX, '') != 'xxx'";
                //    sql += " ORDER BY TransactionDate DESC";
                //}
                //try
                //{
                //    using (SqlConnection cn = new SqlConnection(connectionString))
                //    {
                //        using (SqlCommand cmd = new SqlCommand(sql, cn))
                //        {
                //            var totalShares = 0.0;
                //            cn.Open();
                //            SqlDataReader dr = cmd.ExecuteReader();
                //            while (dr.Read())
                //            {
                //                var transaction = new BuyAndHoldTransactionViewModel();
                //                transaction.Id = Int32.Parse(dr["Id"].ToString());
                //                transaction.BhId = dr["BhId"].ToString();
                //                transaction.TxId = dr["TxId"].ToString();
                //                transaction.Date = (DateTime)dr["TransactionDate"];
                //                transaction.Symbol = dr["Symbol"].ToString();
                //                transaction.Company = dr["Company"].ToString();
                //                transaction.Quantity = dr["Quantity"].ToString();
                //                transaction.Price = dr["Price"].ToString();
                //                transaction.Amount = dr["Amount"].ToString();
                //                transaction.Fee = dr["Fees"].ToString();
                //                transaction.Credit = dr["DebitCredit"].ToString();
                //                transaction.SuspectedType = dr["Transaction"].ToString();
                //                transaction.Type = dr["Type"].ToString();
                //                transaction.Period = dr["Period"].ToString();
                //                transaction.DividendAmount = dr["DividendAmount"].ToString();
                //                transaction.AmtInv = dr["AmountInvested"].ToString();
                //                transaction.NumShares = dr["NumberShares"].ToString();
                //                double numShares = 0;
                //                if (Double.TryParse(dr["NumberShares"].ToString(), out numShares))
                //                {
                //                    totalShares += Math.Round(numShares, 4);
                //                    transaction.TotalShares = totalShares;
                //                }
                //                transaction.BuyPrice = dr["BuyPrice"].ToString();
                //                transaction.XXX = dr["XXX"].ToString();
                //                transaction.Xref = dr["Xref"].ToString();
                //                transaction.Xref2 = dr["Notes"].ToString();
                //                buyAndHoldTransactions.Add(transaction);
                //            }
                //        }
                //    }
                //    return buyAndHoldTransactions.OrderByDescending(p => p.Date).ToList();
            }

               // var model = db.ArtistNews.Take(20);

            catch (Exception ex)
            {
                var w = ex;
                return null;
            }
        }
Exemplo n.º 3
0
        private static AmericanCenturyBuysViewModel BuildTransactionObjects(List<Invest.Domain.Models.AmericanCenturyTransaction> transactions, bool seperateReinvest)
        {
            var nav = GetLatestTickersNav("TWCUX");

            var AmericanCenturyTransactions = new AmericanCenturyBuysViewModel { Nav = nav.ToString("C"), SecurityTicker = "TWCUX", SecurityName = "American Century Ultra", Transactions = new List<AmericanCenturyBuyViewModel>() };
            decimal totalInvested = 0;
            decimal totalReinvested = 0;
            decimal totalShares = 0;
            decimal currentValue = 0;
            decimal totalValue = 0;
            decimal gain = 0;
            foreach (var transaction in transactions)
            {
                var shares = transaction.AmericanCenturyBuy.Shares.Value;
                var amountInvested = transaction.AmericanCenturyBuy.Amount.Value;

                if (transaction.AmericanCenturyBuy.TranType == "Buy" || !seperateReinvest)
                {
                    totalInvested += amountInvested;
                }
                else
                {
                    totalReinvested += amountInvested;
                }

                totalShares += shares;
                currentValue = shares * nav;
                totalValue += currentValue;
                gain = currentValue - transaction.AmericanCenturyBuy.Amount.Value;
                var AmericanCenturyTransaction = new AmericanCenturyBuyViewModel();

                AmericanCenturyTransaction.Id = transaction.AmericanCenturyBuy.Id;
                AmericanCenturyTransaction.BuyDate = transaction.AmericanCenturyBuy.Date.ToShortDateString();
                if (transaction.AmericanCenturyBuy.TranType == "Buy" || !seperateReinvest)
                {
                    AmericanCenturyTransaction.AmountInvested = amountInvested.ToString("C");
                }
                else
                {
                    AmericanCenturyTransaction.AmountReinvested = amountInvested.ToString("C");
                }
                AmericanCenturyTransaction.BuyPrice = transaction.AmericanCenturyBuy.Nav.Value.ToString("C");
                AmericanCenturyTransaction.Shares = transaction.AmericanCenturyBuy.Shares.Value.ToString("F3");

                AmericanCenturyTransaction.CurrentValue = currentValue.ToString("C");
                AmericanCenturyTransaction.Gain = gain.ToString("C");
                AmericanCenturyTransaction.TranType = transaction.AmericanCenturyBuy.TranType.ToString();
                AmericanCenturyTransaction.TotalShares = totalShares.ToString("F3");
                AmericanCenturyTransaction.TotalValue = totalValue.ToString("C");

                if (transaction.AmericanCenturySell != null)
                {
                    var sellPrice = transaction.AmericanCenturySell.SellPrice;
                    var proceeds = shares * sellPrice;

                    AmericanCenturyTransaction.SellDate = transaction.AmericanCenturySell.SellDate.Date.ToShortDateString();
                    AmericanCenturyTransaction.SellPrice = transaction.AmericanCenturySell.SellPrice.ToString("C");
                    AmericanCenturyTransaction.Proceeds = proceeds.ToString("C");
                    AmericanCenturyTransaction.Profit = (proceeds - amountInvested).ToString("C");
                    AmericanCenturyTransaction.CurrentValue = null;
                    AmericanCenturyTransaction.Gain = null;
                }

                AmericanCenturyTransactions.Transactions.Add(AmericanCenturyTransaction);
            }
            AmericanCenturyTransactions.TotalInvested = totalInvested.ToString("C");
            AmericanCenturyTransactions.TotalReinvested = totalReinvested.ToString("C");
            AmericanCenturyTransactions.TotalShares = totalShares.ToString("F3");
            AmericanCenturyTransactions.TotalValue = totalValue.ToString("C");
            return AmericanCenturyTransactions;
        }