Example #1
0
        public List<Quest401kTransactionDto> GetAllTransactions()
        {
            var context = new Invest.Dal.InvestContext();
            var transactions = context.Quest401KTransactions.OrderBy(p => p.Ticker).OrderBy(p => p.Date).Take(500);

            return MapModelToDto(transactions);
        }
Example #2
0
        public bool AddNewTransactionFromMerger(int Id, double shares, DateTime mergerDate, int securityId, int mergerId)
        {
            var db = new InvestContext();
            var security = db.Securities.FirstOrDefault(p => p.Id == securityId);
            var model = db.BuyAndHoldTransactions.FirstOrDefault(p => p.Id == Id);

            var w = new BuyAndHoldTransaction();
            w.OriginalTransactionId = model.Id;
            w.TransactionDate = model.TransactionDate;
            w.TickerSymbol = security.TickerSymbol;
            w.SecurityId = securityId;
            w.OriginalTickerSymbol = model.OriginalTickerSymbol;
            w.OriginalSecurityId = model.SecurityId;
            w.Period = model.Period;
            w.TransactionType = model.TransactionType;
            w.AmountInvested = model.AmountInvested;
            w.NumberShares = shares;
            w.BuyPrice = model.AmountInvested / decimal.Parse(shares.ToString());
            w.ValidFrom = mergerDate;
            w.Notes = model.Notes;
            w.MergerId = mergerId;
            db.BuyAndHoldTransactions.Add(w);
            db.SaveChanges();
            return true;
        }
        public ActionResult BuyPriceDesc()
        {
            var context = new InvestContext();

            var AmericanCenturyTransactions = GetAmericanCenturyLongTermTransactionsList(false);

            return View(AmericanCenturyTransactions);
        }
        public ActionResult BuyPriceDesc(AmericanCenturyBuysViewModel AmericanCenturyTransaction)
        {
            var excludeShortTermTransactions = AmericanCenturyTransaction.ExcludeShortTermTransactions;

            var context = new InvestContext();

            var AmericanCenturyTransactions = GetAmericanCenturyLongTermTransactionsList(excludeShortTermTransactions);
            return View(AmericanCenturyTransactions);
        }
Example #5
0
 public TickerDto GetTickerBySymbol(string symbol)
 {
     var context = new InvestContext();
     if (!string.IsNullOrWhiteSpace(symbol))
     {
         var ticker = context.Tickers.FirstOrDefault(p => p.Symbol == symbol);
         return ticker != null ? ConvertToDto(ticker) : new TickerDto();
     }
     return new TickerDto();
 }
        public TransactionTypeDto GetTransactionType(int id)
        {
            var context = new InvestContext();

            var transactionTypeDtos = new List<TransactionTypeDto>();
            var transactionType = context.BuyAndHoldTransactionTypes.FirstOrDefault(p => p.Id == id);//.OrderBy(p => p.TransactionType1).ToList();

            var Dto = MapToDto(transactionType);

            return Dto;
        }
Example #7
0
        public List<Quest401kTransactionDto> GetTickerTransactions(string ticker)
        {
            var context = new Invest.Dal.InvestContext();

            context.Configuration.LazyLoadingEnabled = false;

            var transactions = context.Quest401KTransactions.Include("SubTransactions").Where(p => p.Ticker == ticker).OrderBy(p => p.Ticker).OrderBy(p => p.Date).Take(500);

            var w = transactions.ToList().First().SubTransactions;

            return MapModelToDto(transactions);
        }
Example #8
0
        public NavDto GetNav(int tickerId)
        {
            var context = new InvestContext();
            //var tickerDto = new TickerDto();
            var nav = context.Navs.OrderByDescending(p => p.Date).FirstOrDefault(p => p.TickerId == tickerId);

            //foreach (var ticker in tickers)
            //{
            var navDto = ConvertToDto(nav);
            //    tickerDtos.Add(tickerDto);
            //}

            return navDto;
        }
Example #9
0
        public List<TickerDto> GetTickers(string text)
        {
            var context = new InvestContext();
            var tickerDtos = new List<TickerDto>();
            //var tickers = context.Tickers.Where(r => r.Symbol.StartsWith(text)).OrderBy(p => p.Symbol).Select(r => new { r.Id, value = r.Symbol }).ToList();
            var tickers = context.Tickers.Where(r => r.Symbol.StartsWith(text)).OrderBy(p => p.Symbol).ToList();
            foreach (var ticker in tickers)
            {
                var tickerDto = ConvertToDto(ticker);
                tickerDtos.Add(tickerDto);
            }

            return tickerDtos;
        }
Example #10
0
        public TickerDto GetTickerById(int id)
        {
            var context = new InvestContext();
            //var tickerDto = new TickerDto();
            var ticker = context.Tickers.FirstOrDefault(p => p.Id == id);

            //foreach (var ticker in tickers)
            //{
                var tickerDto = ConvertToDto(ticker);
            //    tickerDtos.Add(tickerDto);
            //}

            return tickerDto;
        }
Example #11
0
        public List<StatementItemDto> GetStatements(int accountId)
        {
            var context = new InvestContext();
            var statementItemDtos = new List<StatementItemDto>();
            var statementItems = context.StatementItems.OrderBy(p => p.Ticker).ThenByDescending(p=>p.Date); ;//.Where(p => p.AccountId == accountId).OrderBy(p => p.Ticker1.Symbol);

            foreach (var statementItem in statementItems)
            {
                var statementItemDto = ConvertToDto(statementItem);
                statementItemDtos.Add(statementItemDto);
            }

            return statementItemDtos;
        }
Example #12
0
        public List<TickerDto> GetAllTickers()
        {
            var context = new InvestContext();
            var tickerDtos = new List<TickerDto>();
            List<Invest.Domain.Models.Ticker> tickers = context.Tickers.OrderBy(p => p.Name).ToList();

            foreach (var ticker in tickers)
            {
                var tickerDto = ConvertToDto(ticker);
                tickerDtos.Add(tickerDto);
            }

            return tickerDtos;
        }
Example #13
0
        public NavDto GetTicker(string tickerSymbol)
        {
            var context = new InvestContext();
            //var tickerDto = new TickerDto();
            var nav = context.Navs.OrderByDescending(p => p.Date).FirstOrDefault(p => p.Ticker == tickerSymbol);

            //foreach (var ticker in tickers)
            //{
            var navDto = nav != null ? ConvertToDto(nav) : new NavDto();
            //    tickerDtos.Add(tickerDto);
            //}

            return navDto;
        }
Example #14
0
        public List<AccountDto> GetAccounts()
        {
            var context = new InvestContext();
            var accountDtos = new List<AccountDto>();
            List<Invest.Domain.Models.Account> accountModels = context.Accounts.OrderBy(p => p.Name).ToList();

            foreach (var account in accountModels)
            {
                var accountDto = ConvertToDto(account);
                accountDtos.Add(accountDto);
            }

            return accountDtos;
        }
Example #15
0
        public List<TransactionTypeDto> GetTransactionTypes()
        {
            var context = new InvestContext();

            var transactionTypeDtos = new List<TransactionTypeDto>();
            var transactionTypes = context.TransactionTypes.OrderBy(p => p.TransactionType1).ToList();

            foreach (var transactionType in transactionTypes)
            {
                var transactionTypeDto = MapToDto(transactionType);
                transactionTypeDtos.Add(transactionTypeDto);
            }

            return transactionTypeDtos;
        }
Example #16
0
        public List<BuyAndHoldRawTransactionDto> GetBuyAndHoldRawTransactions2(string symbol)
        {
            var buyAndHoldTransactions = new List<BuyAndHoldRawTransactionDto>();

            var db = new 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
                                    .OrderByDescending(p => p.TransactionDate).Take(1000).ToList();
            }
            else
            {
                BuyAndHoldTransactionModels = db.BuyAndHoldRawTransactions.Where(p => p.TickerSymbol == symbol).Where(p => p.TransactionType != "Dividend Tx").Where(p => p.TransactionType != "VOID").Where(p => p.TransactionType != "").Where(p => p.TransactionType != null)
                                    .OrderBy(p => p.TransactionDate).ToList();
            }
            foreach (var buyAndHoldTransactionModel in BuyAndHoldTransactionModels)
            {
                buyAndHoldTransactions.Add(new BuyAndHoldRawTransactionDto
                {
                    Amount = buyAndHoldTransactionModel.Amount,
                    AmountInvested = buyAndHoldTransactionModel.AmountInvested,
                    //BhId = buyAndHoldTransactionModel.BhId,
                    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,
                    TransactionTypeId = buyAndHoldTransactionModel.TransactionTypeId,
                    TransactionType = buyAndHoldTransactionModel.TransactionType,
                    Xref = buyAndHoldTransactionModel.Xref,
                    XXX = buyAndHoldTransactionModel.XXX
                });
            }
            return buyAndHoldTransactions;
        }
Example #17
0
        public Security Update(SecurityDto dto)
        {
            Security model;
            //using (var context = new InvestContext())
            var context = new InvestContext();
            //{
                model = context.Securities.FirstOrDefault(p => p.Id == dto.Id);

                model.Active = dto.Active;
                model.CompanyName = dto.CompanyName;
                model.Notes = dto.Notes;
                model.TickerSymbol = dto.TickerSymbol;
                context.SaveChanges();
            //}
            return model;
        }
Example #18
0
        public HistoricalCompanyName Update(HistoricalCompanyNameDto dto)
        {
            HistoricalCompanyName model;
            //using (var context = new InvestContext())
            var context = new InvestContext();
            //{
            model = context.HistoricalCompanyNames.FirstOrDefault(p => p.Id == dto.Id);

            model.ValidFrom = dto.ValidFrom;
            model.CompanyName = dto.CompanyName;
            //model. = dto.Notes;
            //model.TickerSymbol = dto.TickerSymbol;
            context.SaveChanges();
            //}
            return model;
        }
        public HistoricalTickerSymbol Update(HistoricalTickerSymbolDto dto)
        {
            HistoricalTickerSymbol model;
            //using (var context = new InvestContext())
            var context = new InvestContext();
            //{
            model = context.HistoricalTickerSymbols.FirstOrDefault(p => p.Id == dto.Id);

            //model.Active = dto.Active;
            //model.CompanyName = dto.CompanyName;
            //model.Notes = dto.Notes;
            model.TickerSymbol = dto.TickerSymbol;
            context.SaveChanges();
            //}
            return model;
        }
Example #20
0
        public List<AmericanCenturyBuyDto> GetTransactions()
        {
            var transactions = new List<AmericanCenturyBuyDto>();

            var db = new InvestContext();

            var transactionModels = db.AmericanCenturyBuys
                                    .OrderByDescending(p => p.Date).ToList();

            foreach (var buyModel in transactionModels)
            {
                var w = MapAmericanCenturyBuy(buyModel);
                transactions.Add(w);

            }
            return transactions;
        }
Example #21
0
        public List<AmericanCenturyTransactionDto> GetAmericanCenturyTransactions(bool excludeSoldTransactions)
        {
            var context = new InvestContext();

            var transactions = new List<AmericanCenturyTransactionDto>();

            //TODO ADD LOGIC to faCTO OUT SOLD TRANSACTIONS

            var transactionModels = excludeSoldTransactions ? context.AmericanCenturyTransactions.OrderBy(p => p.AmericanCenturyBuy.Date).ToList()
                : context.AmericanCenturyTransactions.OrderBy(p => p.AmericanCenturyBuy.Date).ToList();

            foreach (var model in transactionModels)
            {
                var dto = MapAmericanCenturyTransaction(model);
                transactions.Add(dto);
            }
            return transactions;
        }
Example #22
0
        public BuyAndHoldTransaction CreateBuyAndHoldTransaction(BuyAndHoldTransactionDto dto)
        {
            var context = new InvestContext();

            var model = new BuyAndHoldTransaction(); // db.BuyAndHoldTransactions.FirstOrDefault(p => p.Id == dto.Id);
            model.RawTransactionId = dto.BuyAndHoldRawId;
            model.OriginalTransactionId = dto.OriginalTransactionId;
            model.TransactionDate = dto.TransactionDate;
            model.SecurityId = dto.SecurityId.HasValue ? dto.SecurityId.Value : 0;
            model.TickerSymbol = dto.TickerSymbol;
            model.OriginalSecurityId = dto.OriginalSecurityId.HasValue ? (int?)dto.OriginalSecurityId.Value : null;
            model.OriginalTickerSymbol = dto.OriginalTickerSymbol;
            model.Period = dto.Period;
            model.TransactionType = dto.TransactionType;
            model.TransactionTypeId = dto.TransactionTypeId;
            model.TransactionApplied = dto.TransactionApplied;
            model.DividendAmount = dto.DividendAmount;
            model.AmountInvested = dto.AmountInvested;
            model.NumberShares = dto.NumberShares;
            model.BuyPrice = dto.BuyPrice;
            model.Split = dto.Split;
            model.ValidFrom = dto.ValidFrom;
            model.ValidTo = dto.ValidTo;
            model.SellId = dto.SellId;
            model.SellDate = dto.SellDate;
            model.Notes = dto.Notes;
            model.Url1 = dto.Url1;
            model.Url2 = dto.Url2;
            model.Url3 = dto.Url3;
            model.NewMergerId = dto.MergerId;
            model.NewSpinOffId = dto.SpinOffId;

            context.BuyAndHoldTransactions.Add(model);
            context.SaveChanges();
            return model;
        }
Example #23
0
        public List<AmericanCenturyTransactionDto> GetAmericanCenturyLongTermTransactions(bool excludeSoldTransactions)
        {
            var context = new InvestContext();

            var transactions = new List<AmericanCenturyTransactionDto>();

            //TODO ADD LOGIC to faCTO OUT SOLD TRANSACTIONS

            var OneYearAgo = DateTime.Now.AddYears(-1);

            var transactionModels = context.AmericanCenturyTransactions.Where(p => p.AmericanCenturyBuy.Date < OneYearAgo).OrderBy(p => p.AmericanCenturyBuy.Date).ToList();

            if (excludeSoldTransactions)
            {
                transactionModels = transactionModels.Where(p => p.AmericanCenturySellId != null).ToList();
            }

            foreach (var model in transactionModels)
            {
                var dto = MapAmericanCenturyTransaction(model);
                transactions.Add(dto);
            }
            return transactions;
        }
Example #24
0
        public List<BuyAndHoldMerger> GetBuyAndHoldMergers()
        {
            var db = new InvestContext();

            return db.BuyAndHoldMergers.ToList();
        }
 public IEnumerable<HistoricalTickerSymbol> GetByTickerSymbol(string symbol)
 {
     var context = new InvestContext();
     return context.HistoricalTickerSymbols.Where(p => p.Security.TickerSymbol == symbol);
 }
 public IEnumerable<HistoricalTickerSymbol> GetBySecurityId(int id)
 {
     var context = new InvestContext();
     return context.HistoricalTickerSymbols.Where(p => p.SecurityId == id);
 }
 public HistoricalTickerSymbol GetById(int id)
 {
     var context = new InvestContext();
     return context.HistoricalTickerSymbols.FirstOrDefault(p => p.Id == id);
 }
 public IEnumerable<HistoricalTickerSymbol> GetAll()
 {
     var context = new InvestContext();
         return context.HistoricalTickerSymbols.OrderBy(p => p.TickerSymbol);
 }
Example #29
0
        public BuyAndHoldRawTransaction GetBuyAndHoldRawTransaction(int id)
        {
            var db = new InvestContext();

            return db.BuyAndHoldRawTransactions.FirstOrDefault(p => p.Id == id);
        }
Example #30
0
 public BuyAndHoldSplit GetBuyAndHoldSplit(int id)
 {
     var db = new InvestContext();
     return db.BuyAndHoldSplits.FirstOrDefault(p => p.Id == id);
 }