Example #1
0
        public async Task <List <BalanceViewModel> > AddEffectiveBalancesTemplate(Guid userId)
        {
            IEnumerable <DateTime> effectiveDates = await _balanceRepository.GetOrderedEffectiveDatesAsync(userId);

            DateTime today = DateTime.UtcNow.Date;
            bool     todayBalancesExists = effectiveDates.Contains(today);

            List <BalanceViewModel> result;

            if (!todayBalancesExists)
            {
                List <ExchangeRateModel> rates = await _exchangeRateService.AddExchangeRatesAsync(userId, today);

                if (effectiveDates.Any())
                {
                    DateTime latestEffectiveDate = effectiveDates.FirstOrDefault();
                    result = await AddBalancesByTemplateAsync(userId, latestEffectiveDate, today);
                }
                else
                {
                    result = await AddAssetsBalancesAsync(userId, today);
                }
            }
            else
            {
                IEnumerable <Balance> balances = await _balanceRepository.GetByEffectiveDateAsync(userId, today);

                result = balances.Select(b => new BalanceViewModel(b)).ToList();
            }

            return(result);
        }