Ejemplo n.º 1
0
        public bool AddBuy(BuyDto buyDto)
        {
            try
            {
                var accountEntity = context.Account.FirstOrDefault(p => p.Id == buyDto.AccountId);
                var buyEntity = new 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,
                };
                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 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 Ticker { Symbol = buyDto.Ticker, tickerGUID = Guid.NewGuid(), type = "", current = true };

                buyEntity.Ticker = buyDto.Ticker;

                buyEntity.TickerGUID = tickerEntity.tickerGUID;

                buyEntity.Transactions.Add(new Transaction { AmtInv = buyDto.AmtInv, NumShares = buyDto.NumShares, buySplitPercent = 1, DateAdded = DateTime.Now, DateUpdated = DateTime.Now});

                context.SaveChanges();
                return true;
            }
            catch(Exception ex)
            {
                throw;

            }
        }
Ejemplo n.º 2
0
        public bool SaveBuy(BuyDto buyDto)
        {
            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;
        }