private IEnumerable <StockPurchase> MapTransactionsToPurchases(ulong userId,
                                                                       List <object[]> transactions,
                                                                       FidelityTransactionColumns columns)
        {
            var purchases = new List <StockPurchase>();

            for (var i = 0; i < transactions.Count; i++)
            {
                try
                {
                    var purchase = new StockPurchase()
                    {
                        Comment      = string.Empty,
                        PurchaseDate = Convert.ToDateTime(transactions[i][columns.RunDate]),
                        Price        = Convert.ToDecimal(transactions[i][columns.Price]),
                        Quantity     = Convert.ToDecimal(transactions[i][columns.Quantity]),
                        Ticker       = Convert.ToString(transactions[i][columns.Symbol]),
                        UserId       = userId
                    };
                    purchases.Add(purchase);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
            return(purchases);
        }
 private void MapCurrentColumnNameToIndex(string columnHeader, FidelityTransactionColumns columns, int index)
 {
     if (columnHeader.Contains(FidelityColumnNames.ACTION))
     {
         columns.Action = index;
     }
     else if (columnHeader.Contains(FidelityColumnNames.PRICE))
     {
         columns.Price = index;
     }
     else if (columnHeader.Contains(FidelityColumnNames.QUANTITY))
     {
         columns.Quantity = index;
     }
     else if (columnHeader.Contains(FidelityColumnNames.SYMBOL))
     {
         columns.Symbol = index;
     }
     else if (columnHeader.Contains(FidelityColumnNames.TRANSACTION_DATE))
     {
         columns.RunDate = index;
     }
     else if (columnHeader.Contains(FidelityColumnNames.SECURITY_DESCRIPTION))
     {
         columns.SecurityDescription = index;
     }
 }
        private List <object[]> GetTransactionsOfSpecificTypesAfterSpecificDate(DataTable transactions,
                                                                                DateTime lastTransactionDateOnRecord,
                                                                                List <string> allowedTypes,
                                                                                FidelityTransactionColumns columns)
        {
            var filteredData = new List <object[]>();

            for (var i = 0; i < transactions.Rows.Count; i++)
            {
                var assumedPurchaseDate = transactions.Rows[i][columns.RunDate];
                var purchaseDate        = DateTime.MinValue;
                var isPurchaseDate      = DateTime.TryParse(assumedPurchaseDate.ToString(), out purchaseDate);
                if (isPurchaseDate)
                {
                    if (purchaseDate.Date > lastTransactionDateOnRecord.Date)
                    {
                        var transactionType = transactions.Rows[i][columns.Action];
                        if (transactionType != null &&
                            transactionType.GetType() == typeof(string) &&
                            DoesTransactionTypeMatch(allowedTypes, transactionType.ToString()) &&
                            !IsSecurityDescriptionCash(transactions.Rows[i][columns.SecurityDescription].ToString())
                            )
                        {
                            filteredData.Add(transactions.Rows[i].ItemArray);
                        }
                    }
                }
            }

            return(filteredData);
        }
        private FidelityTransactionColumns GetColumnMapping(DataTable transactions)
        {
            var columnMapping = new FidelityTransactionColumns();

            for (var i = 0; i < transactions.Rows.Count; i++)
            {
                if (!string.IsNullOrEmpty(transactions.Rows[i][0].ToString()))
                {
                    for (var j = 0; j < transactions.Rows[i].ItemArray.Length; j++)
                    {
                        var columnHeader = transactions.Rows[i][j].ToString();
                        MapCurrentColumnNameToIndex(columnHeader, columnMapping, j);
                    }
                    if (CheckIfColumnIndexesAreSet(columnMapping))
                    {
                        break;
                    }
                }
            }
            return(columnMapping);
        }
 private bool CheckIfColumnIndexesAreSet(FidelityTransactionColumns columnMapping)
 {
     return(columnMapping.GetType().GetProperties().Any(x => Convert.ToInt32(x.GetValue(columnMapping)) > 0));
 }