Example #1
0
        public async Task <List <PortfolioItem> > AllPortfolio(bool withDeleted)
        {
            var dbItems = await _stocksRepository.GetPortfolio(withDeleted);

            var result = _mapper.Map <List <PortfolioItem> >(dbItems);
            var prices = await _stockPriceProvider.GetStockPrices(dbItems.Select(x => x.Ticker).ToList());

            foreach (var item in result)
            {
                var price = prices.SingleOrDefault(x => x.Symbol == item.Ticker);
                if (price != null)
                {
                    item.CurrentPrice = price.Price;
                    item.Change       = (price.Price / item.BuyPrice - 1).ToString("0.##");
                }
            }
            return(result);
        }