Пример #1
0
        public void SellShares(decimal sharesToSell)
        {
            var newTaxlots = new List <Taxlot>();

            foreach (var lot in Taxlots)
            {
                if (sharesToSell > lot.Shares)
                {
                    sharesToSell -= lot.Shares;
                    continue;
                }
                else if (sharesToSell == lot.Shares)
                {
                    sharesToSell = 0;
                    continue;
                }
                else if (sharesToSell < lot.Shares)
                {
                    var newShareQuantity = lot.Shares - sharesToSell;
                    sharesToSell = 0;
                    var newTaxlot = new Taxlot(lot.Ticker, newShareQuantity, lot.PurchasePrice, lot.DatePurchased, lot.SecurityType, Price);
                    newTaxlots.Add(newTaxlot);
                }
            }
            Taxlots = newTaxlots;
        }
Пример #2
0
 /// <summary>
 /// Adds a taxlot to an existing position in some security
 /// </summary>
 /// <param name="taxlotToAdd"></param>
 public void AddToPortfolioDatabase(Taxlot taxlotToAdd)
 {
     foreach (var pos in _myPositions.Where(s => s.Ticker == taxlotToAdd.Ticker))
     {
         pos.Taxlots.Add(taxlotToAdd);
     }
 }
Пример #3
0
        public Position(Taxlot taxlot, Security security)
        {
            if (_taxlots == null)
            {
                _taxlots = new List <Taxlot>();
            }

            if (_taxlots != null)
            {
                Ticker = taxlot.Ticker;
            }

            Taxlots.Add(taxlot);
            Security = security;
        }
        public async Task BuildDatabaseTaxlots()
        {
            if (_localMode)
            {
                Messenger.Default.Send <TaxlotMessage>(new TaxlotMessage(_myTaxlots, true, true));
            }

            using (var connection = new SqlConnection(_storageString))
            {
                var commandText = @"SELECT * FROM MyPortfolio;";

                using (var command = new SqlCommand(commandText, connection))
                {
                    connection.Open();
                    var reader = await Task.Run(() => command.ExecuteReader());

                    while (reader.Read())
                    {
                        Security secType;
                        var      datePurchased = new DateTime();

                        var ticker        = reader.GetString(1);
                        var quantity      = int.Parse(reader.GetString(2));
                        var purchasePrice = decimal.Parse(reader.GetString(3));
                        datePurchased = reader.IsDBNull(4) ? new DateTime(2000, 12, 31) : DateTime.Parse(reader.GetString(4));
                        var securityTypeResult = reader.GetString(5);
                        if (securityTypeResult == "Stock")
                        {
                            secType = new Stock();
                        }
                        else
                        {
                            secType = new MutualFund();
                        }
                        var taxLot = new Taxlot(ticker, quantity, purchasePrice, datePurchased, secType);
                        _myTaxlots.Add(taxLot);
                    }
                }
            }
            Messenger.Default.Send <TaxlotMessage>(new TaxlotMessage(_myTaxlots, true, false));
        }
Пример #5
0
        public List <Taxlot> GetTaxlotsFromDatabase()
        {
            var storageString = ConfigurationManager.AppSettings["StorageConnectionString"];

            using (var connection = new SqlConnection(storageString))
            {
                var commandText = @"SELECT * FROM MyPortfolio;";

                using (var command = new SqlCommand(commandText, connection))
                {
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Security secType;
                        var      datePurchased = new DateTime();

                        var ticker        = reader.GetString(1);
                        var quantity      = int.Parse(reader.GetString(2));
                        var purchasePrice = decimal.Parse(reader.GetString(3));
                        datePurchased = reader.IsDBNull(4) ? new DateTime(2000, 12, 31) : DateTime.Parse(reader.GetString(4));
                        var securityTypeResult = reader.GetString(5);
                        if (securityTypeResult == "Stock")
                        {
                            secType = new Stock();
                        }
                        else
                        {
                            secType = new MutualFund();
                        }
                        var taxLot = new Taxlot(ticker, quantity, purchasePrice, datePurchased, secType);
                        _myTaxlots.Add(taxLot);
                    }
                }
            }
            return(_myTaxlots);
        }
Пример #6
0
 public void AddTaxlot(Taxlot taxlotToAdd)
 {
     Taxlots.Add(taxlotToAdd);
 }