コード例 #1
0
        public async Task <OperationResult <ValuePercent> > AggregatePaperProfit(IEnumerable <int> portfolioIds, int userId)
        {
            var sumProfit = 0;
            var sumInvest = 0;

            var ids = portfolioIds.ToList();

            foreach (var portfolioId in ids)
            {
                var resultProfit = await _portfolioService.GetPaperProfit(portfolioId, userId);

                var resultInvestSum = _balanceService.GetInvestSum(portfolioId, userId);

                if (!resultProfit.IsSuccess)
                {
                    return(resultProfit);
                }

                sumProfit += resultProfit.Result.Value;
                sumInvest += resultInvestSum;
            }

            var percent = FinanceHelpers.DivWithOneDigitRound(sumProfit, sumInvest);

            return(new OperationResult <ValuePercent>()
            {
                IsSuccess = true,
                Message = $"Суммарная бумажная прибыль портфелей(я) c id={string.Join(", ", ids)}",
                Result = new ValuePercent()
                {
                    Value = sumProfit,
                    Percent = percent
                }
            });
        }