示例#1
0
        //        public BhSpinOffItem Create(BhSpinOffDto dto)
        public BhSpinOff Create(BhSpinOffDto dto)
        {
            //      var model = new BhSpinOffItem
            var model = new BhSpinOff
            {
                Id = dto.Id,
                TransactionDate = dto.TransactionDate,
                Notes = dto.Notes,
                TransactionApplied = dto.TransactionApplied,
            };

            var sourceModel = new BhSpinOffSource
            {
                Id = dto.SourceId,
                CostBasisSplit = dto.CostBasisSplit,
                SecurityId = dto.SecurityId,
                TickerSymbol = dto.TickerSymbol,
                Shares = dto.Shares,
                TransactionApplied = dto.SourceTransactionApplied
            };

            model.BhSpinOffSources.Add(sourceModel);

            foreach (var linkDto in dto.SpinOffLinks)
            {
                var linkModel = new BhSpinOffLink
                {
                    Url = linkDto.Url
                };
                model.BhSpinOffLinks.Add(linkModel);
            }

            foreach (var itemDto in dto.SpinOffItems)
            {
                var itemModel = new BhSpinOffItem
                {
                    BhTransactionDate = itemDto.BhTransactionDate,
                    BhTransactionId = itemDto.BhTransactionId,
                    TickerSymbol = itemDto.TickerSymbol,
                    SecurityId = itemDto.SecurityId,
                    Shares = itemDto.Shares,
                    Ratio = itemDto.Ratio,
                    CostBasisSplit = itemDto.CostBasisSplit,
                    TransactionApplied = itemDto.TransactionApplied,
                };

                model.BhSpinOffItems.Add(itemModel);
            }

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

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

            catch (Exception ex)
            {
                var w = ex.Message;
            }

            return model;
        }
示例#2
0
 //BhSpinOffLink
 public BhSpinOffLinkDto MapToDto(BhSpinOffLink model)
 {
     return new BhSpinOffLinkDto
     {
         Id = model.Id,
         SpinOffId = model.SpinOffId,
         Url = model.Url
     };
 }
示例#3
0
 private BhSpinOffLink MapDtoToModel(BhSpinOffLinkDto dto, BhSpinOffLink model)
 {
     model.Url = dto.Url;
     return model;
 }