Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 private BhMergerSource MapDtoToModel(BhMergerDto dto, BhMergerSource model)
 {
     model.Id = dto.SourceId;
     model.BhTransactionId = dto.BhTransactionId;
     model.BhTransactionDate = dto.BhTransactionDate;
     model.SecurityId = dto.SecurityId;
     model.TickerSymbol = dto.TickerSymbol;
     model.Shares = dto.Shares;
     model.TransactionApplied = dto.SourceTransactionApplied;
     return model;
 }