Beispiel #1
0
        //BhMerger
        public BhMergerDto MapToDto(BhMerger model)
        {
            var dto = new BhMergerDto
            {
                Id = model.Id,
                TransactionDate = model.TransactionDate,
                Notes = model.Notes,
                TransactionApplied = model.TransactionApplied,
                MergerItems = MapToDto(model.BhMergerItems),
                MergerLinks = MapToDto(model.BhMergerLinks),
                BuyAndHoldTransactions = _buyAndHoldTransactionDomainMap.MapToDto(model.BuyAndHoldTransactions),
            };

            if (model.BhMergerSources != null && model.BhMergerSources.Count > 0)
            {
                dto.SourceId = model.BhMergerSources.First().Id;
                dto.BhTransactionId = model.BhMergerSources.First().BhTransactionId;
                dto.BhTransactionDate = model.BhMergerSources.First().BhTransactionDate;

                dto.SecurityId = model.BhMergerSources.First().SecurityId;
                dto.TickerSymbol = model.BhMergerSources.First().TickerSymbol;
                dto.Shares = model.BhMergerSources.First().Shares;
                dto.SourceTransactionApplied = model.BhMergerSources.First().TransactionApplied;
            }
            return dto;
        }
Beispiel #2
0
        public BhMerger Create(BhMergerDto dto)
        {
            var model = new BhMerger
            {
                Id = dto.Id,
                TransactionDate = dto.TransactionDate,
                Notes = dto.Notes,
                TransactionApplied = dto.TransactionApplied,
            };

            var sourceModel = new BhMergerSource
            {
                Id = dto.SourceId,
                BhTransactionId = dto.BhTransactionId,
                BhTransactionDate = dto.BhTransactionDate,
                SecurityId = dto.SecurityId,
                TickerSymbol = dto.TickerSymbol,
                Shares = dto.Shares,
                TransactionApplied = dto.SourceTransactionApplied
            };

            model.BhMergerSources.Add(sourceModel);

            foreach (var linkDto in dto.MergerLinks)
            {
                var linkModel = new BhMergerLink
                {
                    Url = linkDto.Url
                };
                model.BhMergerLinks.Add(linkModel);
            }

            foreach (var itemDto in dto.MergerItems)
            {
                var itemModel = new BhMergerItem
                {
                    BhTransactionDate = itemDto.BhTransactionDate,
                    BhTransactionId = itemDto.BhTransactionId,
                    TickerSymbol = itemDto.TickerSymbol,
                    SecurityId = itemDto.SecurityId,
                    Shares = itemDto.Shares,
                    Ratio = itemDto.Ratio,
                    CashPerShare = itemDto.CashPerShare,
                    CashRecieved = itemDto.CashRecieved,
                    CostBasisSplit = itemDto.CostBasisSplit,
                    TransactionApplied = itemDto.TransactionApplied,
                };

                model.BhMergerItems.Add(itemModel);
            }

            _context.BhMergers.Add(model);
            try
            {
                _context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                _context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                var w = ex.Message;
            }

            return model;
        }