예제 #1
0
        public async Task <IActionResult> CreatePortfolio([FromBody] SavePortfolioViewModel portfolioViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var portfolio = mapper.Map <SavePortfolioViewModel, Portfolio>(portfolioViewModel);

            //set some defaults
            //portfolio.Active = false;
            //portfolio.Draft = true;

            repository.Add(portfolio);
            repository.CommitWithWait();

            portfolio = await repository.GetSingleAsync(portfolio.Id);

            BackgroundJob.Enqueue <BackgroundProcessingService>(service =>
                                                                service.ProcessNewPortfolioComponents(portfolio, portfolioViewModel));

            var result = mapper.Map <Portfolio, PortfolioViewModel>(portfolio);

            return(Ok(result));
        }
        public void ProcessNewHoldingComponents(SaveHoldingViewModel components)
        {
            var portfolio = portfolioRepository.GetSingle(p => p.Id == components.PortfolioId);

            var newComps = new SavePortfolioViewModel {
                YahooCode      = components.YahooCode,
                PurchaseAmount = components.PurchaseAmount,
                PurchaseDate   = components.PurchaseDate,
                PurchasePrice  = components.PurchasePrice,
                PurchaseFees   = components.PurchaseFees,
                CustomName     = components.CustomName
            };

            ProcessNewPortfolioComponents(portfolio, newComps);
        }
        public void ProcessNewPortfolioComponents(Portfolio portfolio, SavePortfolioViewModel components)
        {
            Security security = securityRepository.GetSingle(s => s.YahooCode == components.YahooCode);

            if (security == null)
            {
                //var quote = yahooClient.GetRealTimeData(components.YahooCode);

                security = new Security()
                {
                    YahooCode = components.YahooCode,
                    Name      = components.CustomName
                };
                //securityRepository.Add(security);
                context.Add <Security>(security);
            }

            //Save Holding
            Holding holding = new Holding()
            {
                Security      = security,
                PortfolioId   = portfolio.Id,
                CustomName    = security.Name,
                TotalUnits    = components.PurchaseAmount,
                TotalCostBase = (components.PurchaseAmount * components.PurchasePrice) + components.PurchaseFees
            };

            //holdingRepository.Add(holding);
            context.Add <Holding>(holding);

            //Save Parcel
            Parcel parcel = new Parcel()
            {
                Holding        = holding,
                PurchaseDate   = components.PurchaseDate,
                UnitsPurchased = components.PurchaseAmount,
                PurchasePrice  = components.PurchasePrice,
                Brokerage      = components.PurchaseFees
            };

            //parcelRepository.Add(parcel);
            context.Add <Parcel>(parcel);

            //Save Holding Transaction
            HoldingTransaction transaction = new HoldingTransaction()
            {
                Holding         = holding,
                TransactionDate = components.PurchaseDate,
                TransactionType = HoldingTransactionType.Buy,
                Units           = components.PurchaseAmount,
                UnitPrice       = components.PurchasePrice,
                Brokerage       = components.PurchaseFees,
                GeneratedParcel = parcel
            };

            //holdingTransactionRepository.Add(transaction);
            context.Add <HoldingTransaction>(transaction);

            context.SaveChanges();

            DownloadQuotes(security, parcel.PurchaseDate, true);
            UpdatePortfolioTotals(portfolio.Id);
        }
예제 #4
0
 public void CreatePortfolioComponents(Portfolio portfolio, SavePortfolioViewModel portfolioDetails)
 {
 }