public List<BuyAndHoldRawTransactionDto> GetBuyAndHoldRawTransactionsByTickerSymbol(string symbol) { var buyAndHoldTransactions = new List<BuyAndHoldRawTransactionDto>(); var db = new Invest.Dal.InvestContext(); List<BuyAndHoldRawTransaction> BuyAndHoldTransactionModels; //return context.BuyAndHoldTransactions.Where(p => p.Symbol == ticker).Where(p => (p.TransactionId ?? 0) > 0).Where(p => (p.ValidTo ?? tomorrow) > DateTime.Today).OrderByDescending(p => p.TransactionDate).ToList(); if (symbol == "zzz") { BuyAndHoldTransactionModels = db.BuyAndHoldRawTransactions.Where(p => p.XXX != "xxx") .OrderByDescending(p => p.TransactionDate).Take(1000).ToList(); } else { BuyAndHoldTransactionModels = db.BuyAndHoldRawTransactions // .Include("BuyAndHoldTransactionTransactions") .Where(p => p.TickerSymbol == symbol) .OrderBy(p => p.TransactionDate).ToList(); } foreach (var buyAndHoldTransactionModel in BuyAndHoldTransactionModels) { List<BuyAndHoldTransactionTransactionDto> buyAndHoldTransactionTransactionDtos = new List<BuyAndHoldTransactionTransactionDto>(); foreach (var BuyAndHoldTransactionTransaction in buyAndHoldTransactionModel.BuyAndHoldTransactions) { var w = new BuyAndHoldTransactionTransactionDto(); w.AmountInvested = BuyAndHoldTransactionTransaction.AmountInvested; buyAndHoldTransactionTransactionDtos.Add(w); } buyAndHoldTransactions.Add(new BuyAndHoldRawTransactionDto { Amount = buyAndHoldTransactionModel.Amount, AmountInvested = buyAndHoldTransactionModel.AmountInvested, BuyPrice = buyAndHoldTransactionModel.BuyPrice, Company = buyAndHoldTransactionModel.Company, DebitCredit = buyAndHoldTransactionModel.DebitCredit, DividendAmount = buyAndHoldTransactionModel.DividendAmount, Fees = buyAndHoldTransactionModel.Fees, Id = buyAndHoldTransactionModel.Id, Notes = buyAndHoldTransactionModel.Notes, NumberShares = buyAndHoldTransactionModel.NumberShares, Period = buyAndHoldTransactionModel.Period, Price = buyAndHoldTransactionModel.Price, Quantity = buyAndHoldTransactionModel.Quantity, Split = buyAndHoldTransactionModel.Split, TickerSymbol = buyAndHoldTransactionModel.TickerSymbol, SuspectedType = buyAndHoldTransactionModel.SuspectedType, TransactionDate = buyAndHoldTransactionModel.TransactionDate, TransactionType = buyAndHoldTransactionModel.TransactionType, Xref = buyAndHoldTransactionModel.Xref, XXX = buyAndHoldTransactionModel.XXX, ValidFrom = buyAndHoldTransactionModel.ValidFrom, ValidTo = buyAndHoldTransactionModel.ValidTo, TransactionApplied = buyAndHoldTransactionModel.TransactionApplied ?? false, BuyAndHoldTransactionTransactionsDto = buyAndHoldTransactionTransactionDtos }); } return buyAndHoldTransactions; }
public List<BuyAndHoldRawTransactionDto> GetBuyAndHoldRawTransactionsBySecurityId(int id) { var buyAndHoldTransactions = new List<BuyAndHoldRawTransactionDto>(); var db = new InvestContext(); List<BuyAndHoldRawTransaction> BuyAndHoldTransactionModels; BuyAndHoldTransactionModels = db.BuyAndHoldRawTransactions // .Include("BuyAndHoldTransactionTransactions") .Where(p => p.SecurityId == id) .OrderBy(p => p.TransactionDate).ToList(); foreach (var buyAndHoldTransactionModel in BuyAndHoldTransactionModels) { List<BuyAndHoldTransactionTransactionDto> buyAndHoldTransactionTransactionDtos = new List<BuyAndHoldTransactionTransactionDto>(); foreach (var BuyAndHoldTransactionTransaction in buyAndHoldTransactionModel.BuyAndHoldTransactions) { var w = new BuyAndHoldTransactionTransactionDto(); w.AmountInvested = BuyAndHoldTransactionTransaction.AmountInvested; buyAndHoldTransactionTransactionDtos.Add(w); } buyAndHoldTransactions.Add(new BuyAndHoldRawTransactionDto { Amount = buyAndHoldTransactionModel.Amount, AmountInvested = buyAndHoldTransactionModel.AmountInvested, BuyPrice = buyAndHoldTransactionModel.BuyPrice, Company = buyAndHoldTransactionModel.Company, DebitCredit = buyAndHoldTransactionModel.DebitCredit, DividendAmount = buyAndHoldTransactionModel.DividendAmount, Fees = buyAndHoldTransactionModel.Fees, Id = buyAndHoldTransactionModel.Id, Notes = buyAndHoldTransactionModel.Notes, NumberShares = buyAndHoldTransactionModel.NumberShares, Period = buyAndHoldTransactionModel.Period, Price = buyAndHoldTransactionModel.Price, Quantity = buyAndHoldTransactionModel.Quantity, Split = buyAndHoldTransactionModel.Split, TickerSymbol = buyAndHoldTransactionModel.TickerSymbol, SuspectedType = buyAndHoldTransactionModel.SuspectedType, TransactionDate = buyAndHoldTransactionModel.TransactionDate, TransactionType = buyAndHoldTransactionModel.TransactionType, TransactionTypeId = buyAndHoldTransactionModel.TransactionTypeId, Xref = buyAndHoldTransactionModel.Xref, XXX = buyAndHoldTransactionModel.XXX, BuyAndHoldTransactionTransactionsDto = buyAndHoldTransactionTransactionDtos }); } return buyAndHoldTransactions; }