Ejemplo n.º 1
0
        public static async Task <List <BondReport> > GetBondReports(int userId, IPortfolioService portfolioService, int portfolioId)
        {
            var bonds = portfolioService.GetBonds(portfolioId, userId);

            var bondReports = new List <BondReport>();

            foreach (var bondInfo in bonds)
            {
                var name = await bondInfo.GetName();

                var price = await bondInfo.GetPrice();

                var percentChange = await bondInfo.GetPriceChange();

                var allPrice = await bondInfo.GetAllPrice();

                var paperProfit = await bondInfo.GetPaperProfit();

                var paperProfitPercent = await bondInfo.GetPaperProfitPercent();

                var updateTime = await bondInfo.GetUpdateTime();

                var bondReport = new BondReport()
                {
                    Name               = name,
                    Ticket             = bondInfo.Ticket,
                    Price              = price,
                    PriceChange        = FinanceHelpers.GetPriceDouble(percentChange),
                    AllPrice           = FinanceHelpers.GetPriceDouble(allPrice),
                    BoughtPrice        = FinanceHelpers.GetPriceDouble(bondInfo.BoughtPrice),
                    Amount             = bondInfo.Amount,
                    PaidPayments       = FinanceHelpers.GetPriceDouble(bondInfo.GetSumPayments()),
                    PaperProfit        = FinanceHelpers.GetPriceDouble(paperProfit),
                    PaperProfitPercent = paperProfitPercent,
                    UpdateTime         = updateTime,
                    NearestPayment     = bondInfo.GetNearestPayment(),
                    HasAmortized       = bondInfo.HasAmortized,
                    AmortizationDate   = bondInfo.AmortizationDate
                };

                bondReports.Add(bondReport);
            }

            return(bondReports);
        }
 public IEnumerable <BondInfo> AggregateBonds(IEnumerable <int> portfolioIds, int userId)
 {
     return(portfolioIds.SelectMany(portfolioId => _portfolioService.GetBonds(portfolioId, userId)));
 }