コード例 #1
0
ファイル: BuyAndHoldDal.cs プロジェクト: dcmuir01/Invest
        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;
        }
コード例 #2
0
        public BuyAndHoldTransactionDto MapToDto(BuyAndHoldTransaction model)
        {
            var dto = new BuyAndHoldTransactionDto
            {
                Id = model.Id,
                BuyAndHoldRawId = model.RawTransactionId,
                OriginalTransactionId = model.OriginalTransactionId,
                TransactionDate = model.TransactionDate,
                TickerSymbol = model.TickerSymbol,
                SecurityId = model.SecurityId,
                OriginalTickerSymbol = model.OriginalTickerSymbol,
                OriginalSecurityId = model.OriginalSecurityId,
                Period = model.Period,
                TransactionApplied = model.TransactionApplied ?? false,
                DividendAmount = model.DividendAmount,
                AmountInvested = model.AmountInvested,
                NumberShares = model.NumberShares,
                BuyPrice = model.BuyPrice,
                Split = model.Split,
                ValidFrom = model.ValidFrom,
                ValidTo = model.ValidTo,
                SellDate = model.SellDate,
                SellId = model.SellId,
                Notes = model.Notes,
                TransactionType = model.TransactionType,
                TransactionTypeId = model.TransactionTypeId,
                MergerId = model.NewMergerId,
                SpinOffId = model.NewSpinOffId,
                SplitId = model.SplitId,
            };

            //if (model.OriginalTransaction != null)
            //{
            //    dto.OriginalTransaction = MapToDto(model.OriginalTransaction);

            //    //TODO - What is this for?

            //    //if (!model.BuyPrice.HasValue)
            //    //{
            //    //    dto.BuyPrice = model.OriginalTransaction.BuyPrice;
            //    //}

            //    //if (!model.NumberShares.HasValue)
            //    //{
            //    //    dto.NumberShares = model.OriginalTransaction.NumberShares;
            //    //}
            //}
            return dto;
        }
コード例 #3
0
ファイル: BuyAndHoldDal.cs プロジェクト: dcmuir01/Invest
        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;
        }