예제 #1
0
        public ActionResult Create(NewBuyViewModel buyViewModel)
        {
            try
            {
                var buyDto = new Invest.BusinessLogic.Service.Contract.Dtos.BuyDto();
                Mapper.Map(buyViewModel, buyDto);

                _buyService.AddBuy(buyDto);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
예제 #2
0
        public bool AddBuy(BuyDto buyDto)
        {
            try
            {
                var context = new InvestContext();
                var accountEntity = context.Accounts.FirstOrDefault(p => p.Id == buyDto.AccountId);
                var buyEntity = new Invest.Domain.Models.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,
                };
                Invest.Domain.Models.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 Invest.Domain.Models.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 Invest.Domain.Models.Ticker { Symbol = buyDto.Ticker, tickerGUID = Guid.NewGuid(), type = "", current = true };

                buyEntity.Ticker = buyDto.Ticker;

                buyEntity.TickerGUID = tickerEntity.tickerGUID;

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

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

            }
        }
예제 #3
0
 public void UpdateBuy(BuyDto buy)
 {
     throw new NotImplementedException();
 }
예제 #4
0
        public bool SaveBuy(BuyDto buyDto)
        {
            var context = new InvestContext();
            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;
        }
예제 #5
0
 private Invest.BusinessLogic.Service.Contract.Dtos.BuyDto ConvertToDto(BuyViewModel buyViewModel)
 {
     var buyDto = new Invest.BusinessLogic.Service.Contract.Dtos.BuyDto();
     buyDto.TransactionTypeId = buyViewModel.TransactionTypeId;
     buyDto.AddedBy = buyViewModel.AddedBy;
     //buyDto.AmtInv = buyViewModel.AmtInv;
     buyDto.AmtInv = decimal.Parse(buyViewModel.AmtInv);
     buyDto.BrokerId = buyViewModel.BrokerId;
     //buyDto.BrokerGUID = buy.BrokerGUID;
     buyDto.BuyCommission = buyViewModel.BuyCommission;
     buyDto.BuyDate = buyViewModel.BuyDate.Value;
     buyDto.BuyGUID = buyViewModel.BuyGUID;
     buyDto.BuyPrice = decimal.Parse(buyViewModel.BuyPrice);
     buyDto.BuyType = buyViewModel.BuyType;
     buyDto.Comments = buyViewModel.Comments;
     buyDto.DateAdded = buyViewModel.DateAdded;
     buyDto.DateModified = buyViewModel.DateModified;
     buyDto.DividendAmount = decimal.Parse(buyViewModel.DividendAmount);
     buyDto.Id = buyViewModel.Id;
     //buyDto.InvestmentClassification = buy.InvestmentClassification;
     //buyDto.InvestmentClassificationGuid = buy.InvestmentClassificationGuid;
     buyDto.ModifiedBy = buyViewModel.ModifiedBy;
     buyDto.NumShares = decimal.Parse(buyViewModel.NumShares);
     buyDto.orderby = buyViewModel.orderby;
     buyDto.OriginalBuyGUID = buyViewModel.OriginalBuyGUID;
     buyDto.refID = buyViewModel.refID;
     //buyDto.SubTransactionType = buy.SubTransactionType;
     //buyDto.SubTransactionTypeGuid = buy.SubTransactionTypeGuid;
     buyDto.Ticker = buyViewModel.Ticker;
     // public Ticker Ticker1 { get; set; }
     //buyDto.TickerGUID = buy.TickerGUID;
     buyDto.TickerId = buyViewModel.TickerId ?? 0;
     //buyDto.TranGUID = buy.TranGUID;
     buyDto.TransactionType = buyViewModel.TransactionType;
     buyDto.TransactionTypeId = buyViewModel.TransactionTypeId;
     return buyDto;
 }
예제 #6
0
        public ActionResult Edit(BuyViewModel buyViewModel)
        {
            try
            {
                var buyDto = new BuyDto();
                Mapper.Map(buyViewModel, buyDto);

                var success = _buyService.SaveBuy(buyDto);

                return RedirectToAction("Index");
            }
            catch
            {
                return View(buyViewModel);
            }
        }