Ejemplo n.º 1
0
        public async Task <List <BalanceTotalChangeModel> > GetUserBalanceChangesAsync(Guid userId, int count)
        {
            IEnumerable <DateTime> effectivateDates = await _balanceRepository.GetOrderedEffectiveDatesAsync(userId);

            IEnumerable <DateTime> filterEffectiveDates = effectivateDates.Take(count);

            IEnumerable <UserCurrency> userCurrencies = await _userCurrencyRepository.GetByUserIdAsync(userId);

            string primaryCurrency = userCurrencies.Where(uc => uc.IsPrimary).Select(uc => uc.Currency).FirstOrDefault();

            IEnumerable <Balance> balances = await _balanceRepository.GetAllAsync(userId);

            List <Balance> balancesToDate = balances.Where(b => b.EffectiveDate <= filterEffectiveDates.Last()).ToList();

            List <BalanceTotalChangeModel> result = new List <BalanceTotalChangeModel>();

            foreach (var currency in userCurrencies)
            {
                List <BalanceTotalModel> values = new List <BalanceTotalModel>();

                foreach (var effectiveDate in filterEffectiveDates)
                {
                    var effectiveBalances = balances.Where(b => b.EffectiveDate == effectiveDate).ToList();

                    BalanceTotalModel balanceTotal = await _balanceTotalCalculator
                                                     .CalculateAsync(userId, effectiveBalances, currency.Currency, primaryCurrency, effectiveDate);

                    values.Add(balanceTotal);
                }

                result.Add(new BalanceTotalChangeModel(currency.Currency, values));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <List <BalanceTotalModel> > CalculateTotalsAsync(Guid userId, IEnumerable <Balance> balances, DateTime effectiveDate)
        {
            IEnumerable <UserCurrency> userCurrencies = await _userCurrencyRepository.GetByUserIdAsync(userId);

            string primaryCurrency = userCurrencies.Where(uc => uc.IsPrimary).Select(uc => uc.Currency).FirstOrDefault();

            List <BalanceTotalModel> result = new List <BalanceTotalModel>();

            foreach (var uc in userCurrencies)
            {
                BalanceTotalModel totals = await _balanceTotalCalculator
                                           .CalculateAsync(userId, balances, uc.Currency, primaryCurrency, effectiveDate);

                result.Add(totals);
            }

            return(result);
        }