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 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; }
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 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; }
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; }
public bool UpdateTransactionValidTo(int Id, DateTime mergerDate, int mergerId) { var db = new InvestContext(); var model = db.BuyAndHoldTransactions.FirstOrDefault(p => p.Id == Id); model.ValidTo = mergerDate; model.MergerId = mergerId; db.SaveChanges(); return true; }
public BuyAndHoldRawTransaction UpdateBuyAndHoldRawTransaction(BuyAndHoldRawTransactionDto dto) { var db = new InvestContext(); var model = db.BuyAndHoldRawTransactions.FirstOrDefault(p => p.Id == dto.Id); model.Xref = dto.Xref; model.OriginalRawTransactionId = dto.OriginalRawTransactionId; model.TransactionDate = dto.TransactionDate.Value; model.SecurityId = dto.SecurityId.Value; model.TickerSymbol = dto.TickerSymbol; model.OriginalSecurityId = dto.OriginalSecurityId.HasValue ? (int?)dto.OriginalSecurityId.Value : null; model.OriginalTickerSymbol = dto.OriginalTickerSymbol; model.Company = dto.Company; model.Description = dto.Description; model.Quantity = dto.Quantity; model.Price = dto.Price; model.Amount = dto.Amount; model.Fees = dto.Fees; model.DebitCredit = dto.DebitCredit; model.SuspectedType = dto.SuspectedType; 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.SellDate = dto.SellDate; model.SellId = dto.SellId; model.Notes = dto.Notes; model.XXX = dto.XXX; db.SaveChanges(); return model; }
public bool UpdateBuyAndHoldMerger(BuyAndHoldMergerDto dto) { var db = new InvestContext(); var model = db.BuyAndHoldMergers.FirstOrDefault(p => p.Id == dto.Id); model.TransactionDate = dto.TransactionDate; model.BuyAndHoldTransactionId_In = dto.BuyAndHoldTransactionId_In; model.TickerSymbol_In = dto.TickerSymbol_In; model.SecurityId_In = dto.SecurityId_In; model.Type_In = dto.Type_In; model.AmountInvested_In = dto.AmountInvested_In; model.NumberShares_In = dto.NumberShares_In; model.BuyPrice_In = dto.BuyPrice_In; model.BuyAndHoldTransactionId_Out = dto.BuyAndHoldTransactionId_Out; model.TickerSymbol_Out = dto.TickerSymbol_Out; model.SecurityId_Out = dto.SecurityId_Out; model.Type_Out = dto.Type_Out; model.AmountInvested_Out = dto.AmountInvested_Out; model.NumberShares_Out = dto.NumberShares_Out; model.BuyPrice_Out = dto.BuyPrice_Out; model.TransactionApplied = dto.TransactionApplied; model.ExchangeRate = dto.ExchangeRate; model.Notes = dto.Notes; model.Url1 = dto.Url1; model.Url2 = dto.Url2; model.Url3 = dto.Url3; db.SaveChanges(); return true; }
public bool SplitTransaction(BuyAndHoldSplitTransactionDto dto) { using (var context = new InvestContext()) { var buyAndHoldTransactionTransaction1 = new BuyAndHoldTransactionTransaction { AmountInvested = dto.AmountInvested1, NumberShares = dto.NumberShares1, BuyId = dto.Id, BuySplitPercent = dto.SplitPercent / 100, BuyCommission = 0, DateAdded = DateTime.Now, DateUpdated = DateTime.Now, TransactionGuid = new Guid(), BuyGuid = new Guid() }; context.BuyAndHoldTransactionTransactions.Add(buyAndHoldTransactionTransaction1); var buyAndHoldTransactionTransaction2 = new BuyAndHoldTransactionTransaction { AmountInvested = dto.AmountInvested2, NumberShares = dto.NumberShares2, BuyId = dto.Id, BuySplitPercent = (100 - dto.SplitPercent) / 100, BuyCommission = 0, DateAdded = DateTime.Now, DateUpdated = DateTime.Now, TransactionGuid = new Guid(), BuyGuid = new Guid() }; context.BuyAndHoldTransactionTransactions.Add(buyAndHoldTransactionTransaction2); context.SaveChanges(); } return true; }
public bool AddBuy(BuyDto buyDto) { try { var context = new InvestContext(); var accountEntity = context.Accounts.FirstOrDefault(p => p.Id == buyDto.AccountId); var buyEntity = new Invest.Domain.Models.Buy { Account = accountEntity, TransactionTypeId = buyDto.TransactionTypeId, TranType = buyDto.TransactionType, AddedBy = buyDto.AddedBy, AmtInv = buyDto.AmtInv, BuyCommission = buyDto.BuyCommission, BuyDate = buyDto.BuyDate, BuyPrice = buyDto.BuyPrice, BuyType = buyDto.BuyType, Comments = buyDto.Comments, DividendAmount = buyDto.DividendAmount, ModifiedBy = buyDto.ModifiedBy, NumShares = buyDto.NumShares, orderby = buyDto.orderby, OriginalBuyGUID = buyDto.OriginalBuyGUID, refID = buyDto.refID, DateAdded = DateTime.Now, DateModified = DateTime.Now, BuyGUID = Guid.NewGuid(), InvestmentClassification = accountEntity.InvestmentClassification, InvestmentClassificationGuid = accountEntity.InvestmentClassificationGuid, SubAccount = accountEntity.SubAccount, SubAccountGuid = accountEntity.SubAccountGuid, Broker = accountEntity.Broker, BrokerGUID = accountEntity.BrokerGUID, }; Invest.Domain.Models.Ticker tickerEntity; // public Ticker Ticker1 { get; set; } if (buyDto.Ticker.Length > 0) { tickerEntity = context.Tickers.FirstOrDefault(p => p.Symbol == buyDto.Ticker); if (tickerEntity == null) { tickerEntity = new Invest.Domain.Models.Ticker { Symbol = buyDto.Ticker, tickerGUID = Guid.NewGuid(), type = "", current = true }; } } else { tickerEntity = context.Tickers.FirstOrDefault(p => p.Id == buyDto.TickerId); } buyEntity.Ticker1 = (tickerEntity != null) ? tickerEntity : new Invest.Domain.Models.Ticker { Symbol = buyDto.Ticker, tickerGUID = Guid.NewGuid(), type = "", current = true }; buyEntity.Ticker = buyDto.Ticker; buyEntity.TickerGUID = tickerEntity.tickerGUID; buyEntity.Transactions.Add(new Invest.Domain.Models.Transaction { AmtInv = buyDto.AmtInv, NumShares = buyDto.NumShares, buySplitPercent = 1, DateAdded = DateTime.Now, DateUpdated = DateTime.Now }); context.SaveChanges(); return true; } catch (Exception ex) { throw; } }
public bool SaveBuy(BuyDto buyDto) { var context = new InvestContext(); var buyEntity = context.Buys.FirstOrDefault(p => p.Id == buyDto.Id); buyEntity.TransactionTypeId = buyDto.TransactionTypeId; buyEntity.AddedBy = buyDto.AddedBy; buyEntity.AmtInv = buyDto.AmtInv; // buyEntity.Broker = buyDto.Broker; // buyEntity.BrokerGUID = buyDto.BrokerGUID; // buyEntity.BuyCommission = buyDto.BuyCommission; buyEntity.BuyDate = buyDto.BuyDate; buyEntity.BuyGUID = buyDto.BuyGUID; buyEntity.BuyPrice = buyDto.BuyPrice; buyEntity.BuyType = buyDto.BuyType; buyEntity.Comments = buyDto.Comments; buyEntity.DateAdded = buyDto.DateAdded; buyEntity.DateModified = buyDto.DateModified; buyEntity.DividendAmount = buyDto.DividendAmount; //buyEntity.Id = buyDto.Id; // buyEntity.InvestmentClassification = buyDto.InvestmentClassification; // buyEntity.InvestmentClassificationGuid = buyDto.InvestmentClassificationGuid; buyEntity.ModifiedBy = buyDto.ModifiedBy; buyEntity.NumShares = buyDto.NumShares; buyEntity.orderby = buyDto.orderby; buyEntity.OriginalBuyGUID = buyDto.OriginalBuyGUID; buyEntity.refID = buyDto.refID; // buyEntity.SubTransactionType = buyDto.SubTransactionType; // buyEntity.SubTransactionTypeGuid = buyDto.SubTransactionTypeGuid; buyEntity.Ticker = buyDto.Ticker; // public Ticker Ticker1 { get; set; } //buyEntity.TickerGUID = buyDto.TickerGUID; buyEntity.TickerId = buyDto.TickerId; //buyEntity.TranGUID = buyDto.TranGUID; buyEntity.TranType = buyDto.TransactionType; buyEntity.TransactionTypeId = buyDto.TransactionTypeId; context.SaveChanges(); return true; }
public bool UpdateDividend(int id, int reinvestId, int receivedId, string price, string quantity, string dividendReceived, string dividendReinvested, int taxId, string taxAmount) { var txId = string.Empty; int? xref; using (var context = new InvestContext()) { var buyTransaction = context.BuyAndHoldRawTransactions.First(p => p.Id == id); buyTransaction.TransactionType = "Dividend - Buy"; buyTransaction.DividendAmount = decimal.Parse(dividendReceived); buyTransaction.AmountInvested = decimal.Parse(dividendReinvested); buyTransaction.NumberShares = double.Parse(quantity); buyTransaction.BuyPrice = decimal.Parse(price.Replace("$", "")); buyTransaction.XXX = "XXX"; xref = buyTransaction.Id; if (taxId > 0) { var taxTransaction = context.BuyAndHoldRawTransactions.First(p => p.Id == taxId); taxTransaction.TransactionType = "Dividend Foreign Tax"; taxTransaction.XXX = "XXX"; taxTransaction.Xref = xref; } if (reinvestId > 0) { var reinvestTransaction = context.BuyAndHoldRawTransactions.First(p => p.Id == reinvestId); reinvestTransaction.TransactionType = "Dividend Tx"; reinvestTransaction.XXX = "XXX"; reinvestTransaction.Xref = xref; } var receivedTransaction = context.BuyAndHoldRawTransactions.First(p => p.Id == receivedId); receivedTransaction.TransactionType = "Dividend Tx"; receivedTransaction.XXX = "XXX"; receivedTransaction.Xref = xref; context.SaveChanges(); return true; } }
public bool SaveTicker(TickerDto tickerDto) { var context = new InvestContext(); //var tickerDto = new TickerDto(); //var ticker = context.Tickers.FirstOrDefault(p => p.Id == id); //foreach (var ticker in tickers) //{ // var tickerModel = ConvertToModel(tickerDto); // tickerDtos.Add(tickerDto); //} // var id = Int32.Parse(ticker.Id); var Ticker = context.Tickers.FirstOrDefault(p => p.Id == tickerDto.Id); Ticker.Name = tickerDto.Name; Ticker.Symbol = tickerDto.Symbol; Ticker.Active = tickerDto.Active; Ticker.BCFirstDate = tickerDto.BCFirstDate; Ticker.BH = tickerDto.BH; Ticker.CBSFirstDate = tickerDto.CBSFirstDate; Ticker.Comments = tickerDto.Comments; Ticker.component = tickerDto.component; Ticker.current = tickerDto.current; Ticker.DateAdded = tickerDto.DateAdded; Ticker.DateModified = tickerDto.DateModified; Ticker.endDate = tickerDto.endDate; Ticker.FirstBuy = tickerDto.FirstBuy; Ticker.InceptionDate = tickerDto.InceptionDate; Ticker.LastSell = tickerDto.LastSell; Ticker.MCFirstDate = tickerDto.MCFirstDate; Ticker.priceDecimal = tickerDto.priceDecimal; // public System.Data.Objects.DataClasses.EntityCollection<Sell> Sells { get; set; } Ticker.shareDecimal = tickerDto.shareDecimal; Ticker.startDate = tickerDto.startDate; Ticker.TickerBC = tickerDto.TickerBC; Ticker.TickerBH = tickerDto.TickerBH; Ticker.tickerGUID = tickerDto.tickerGUID; Ticker.TickerYahoo = tickerDto.TickerYahoo; Ticker.type = tickerDto.Type; context.SaveChanges(); return true; }
public bool UpdateTransferOut(int id) { int? xref; using (var context = new InvestContext()) { var x = context.BuyAndHoldRawTransactions.First(p => p.Id == id); x.TransactionType = "Transfer Out"; x.NumberShares = double.Parse(x.Quantity.Replace("(", "-").Replace(")", "")); x.XXX = "XXX"; xref = x.Id; context.SaveChanges(); return true; } }
public bool UpdateSplit(int id, string quantity, string ratio) { using (var context = new InvestContext()) { var Transaction = context.BuyAndHoldRawTransactions.First(p => p.Id == id); Transaction.TransactionType = "Split"; Transaction.Split = ratio; Transaction.NumberShares = double.Parse(quantity.Replace("(", "-").Replace(")", "")); Transaction.XXX = "XXX"; context.SaveChanges(); return true; } }
public bool UpdateSell(int id, int sellTxId, string price, string quantity, string proceeds) { var txId = string.Empty; int? xref; double _quantity = double.Parse(quantity.Replace("(", "-").Replace(")", "")); decimal _proceeds = decimal.Parse(proceeds); decimal _price = string.IsNullOrWhiteSpace(price) ? Math.Abs(_proceeds / decimal.Parse(_quantity.ToString())) : decimal.Parse(price.Replace("$", "")); using (var context = new InvestContext()) { var x = context.BuyAndHoldRawTransactions.First(p => p.Id == id); x.TransactionType = "Sell"; x.Period = string.Empty; x.AmountInvested = _proceeds; x.NumberShares = _quantity; x.BuyPrice = _price; x.XXX = "XXX"; xref = x.Id; if (sellTxId > 0) { var y = context.BuyAndHoldRawTransactions.First(p => p.Id == sellTxId); y.TransactionType = "Sell Tx"; y.XXX = "XXX"; y.Period = string.Empty; y.Xref = xref; } context.SaveChanges(); return true; } }
public bool UpdateMerger(int id, string quantity) { using (var context = new InvestContext()) { var Transaction = context.BuyAndHoldRawTransactions.First(p => p.Id == id); if (quantity.IndexOf("(") > -1) { Transaction.TransactionType = "Merger Out"; } else { Transaction.TransactionType = "Merger In"; } Transaction.NumberShares = double.Parse(quantity.Replace("(", "-").Replace(")", "")); Transaction.XXX = "XXX"; context.SaveChanges(); return true; } }
public bool UpdateDividendNonBuy(int id, string dividendReceived) { using (var context = new InvestContext()) { var x = context.BuyAndHoldRawTransactions.First(p => p.Id == id); x.TransactionType = "Dividend - Non Buy"; x.DividendAmount = decimal.Parse(dividendReceived); x.XXX = "XXX"; context.SaveChanges(); return true; } }
public JsonResult SubmitSellTransaction(DateTime sellDate, string shares, string nav, string transactions) { var soldTransactions = new JavaScriptSerializer().Deserialize<List<SellTransaction>>(transactions); var context = new InvestContext(); var americanCenturySell = new Invest.Domain.Models.AmericanCenturySell { Ticker = new Guid(), //"TWCUX"; SellAmtInv = 100, NumShares = decimal.Parse(shares), SellPrice = decimal.Parse(nav), SellDate = sellDate, SellCommission = 0, SellProceeds = 100, Sell = true, DateAdded = DateTime.Today, DateUpdated = DateTime.Today }; context.AmericanCenturySells.Add(americanCenturySell); context.SaveChanges(); foreach (var sellTransaction in soldTransactions) { var id = Int32.Parse(sellTransaction.id); var AmericanCenturyTransaction = context.AmericanCenturyTransactions.First(p => p.AmericanCenturyBuyId == id); AmericanCenturyTransaction.AmericanCenturySellId = americanCenturySell.Id; AmericanCenturyTransaction.SellProceeds = decimal.Parse(sellTransaction.itemSellProceed); AmericanCenturyTransaction.SellSplitPercent = decimal.Parse(sellTransaction.itemSplitPrecent); AmericanCenturyTransaction.SellCommission = decimal.Parse(sellTransaction.itemSellCommission); } context.SaveChanges(); var success = true; return Json(success); }
public bool UpdateBuy(int id, string price, string quantity, string amountInvested) { using (var context = new InvestContext()) { var x = context.BuyAndHoldRawTransactions.Where(p => p.Id == id).FirstOrDefault(); x.TransactionType = "Buy"; x.AmountInvested = decimal.Parse(amountInvested); x.NumberShares = double.Parse(quantity); x.BuyPrice = decimal.Parse(price.Replace("$", "")); x.XXX = "XXX"; context.SaveChanges(); } return true; }