Beispiel #1
0
        public async Task WhenIGetTodayBalances()
        {
            DateTime today = DateTime.UtcNow.Date;

            BalancesViewModel balances = await _context.BalanceService.GetUserEffectiveBalancesAsync(_userContext.UserId, today);

            _balances = balances.Items.ToList();
        }
        public async Task ThenBalanceForTodayExists()
        {
            DateTime          today    = DateTime.UtcNow.Date;
            BalancesViewModel balances = await _context.BalanceService.GetUserEffectiveBalancesAsync(_userContext.UserId, today);

            bool exists = balances.Count > 0;

            exists.Should().Be(true);
        }
Beispiel #3
0
        public async Task ThenBalanceDeleted()
        {
            BalancesViewModel balances = await _balanceFeatureContext.BalanceService
                                         .GetUserEffectiveBalancesAsync(_userContext.UserId, _effectiveDate);

            bool exists = balances.Items.Any(b => b.Id == _balanceToDeleteId);

            exists.Should().Be(false);
        }
Beispiel #4
0
        public async Task GivenISpecifiedBalanceToDelete(string assetName)
        {
            AssetViewModel asset = await _assetFeatureContext.AssetService
                                   .GetAssetByNameAsync(_userContext.UserId, assetName);

            BalancesViewModel balances = await _balanceFeatureContext.BalanceService
                                         .GetUserEffectiveBalancesAsync(_userContext.UserId, _effectiveDate);

            BalanceViewModel balance = balances.Items.Single(b => b.Asset.Name == asset.Name && b.EffectiveDate == _effectiveDate);

            _balanceToDeleteId = balance.Id.Value;
        }
Beispiel #5
0
        public async Task WhenIUpdateBalanceOfAsset(string assetName)
        {
            DateTime       today = DateTime.UtcNow.Date;
            AssetViewModel asset = await _assetFeatureContext.AssetService.GetAssetByNameAsync(_userContext.UserId, assetName);

            BalancesViewModel balances = await _balanceFeatureContext.BalanceService
                                         .GetUserEffectiveBalancesAsync(_userContext.UserId, today);

            BalanceViewModel balance = balances.Items.Single(b => b.Asset.Name.Equals(assetName, StringComparison.OrdinalIgnoreCase));

            _updatedBalance = await _balanceFeatureContext.BalanceService
                              .UpdateBalanceAsync(_userContext.UserId, balance.Id.Value, _balanceUpdateModel);
        }
Beispiel #6
0
        public async Task <ActionResult <BalancesViewModel> > GetCurrentUserEffectiveBalances(DateTime effectiveDate)
        {
            UserViewModel user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(HandleUserNotFoundResult());
            }

            BalancesViewModel result = await _balanceService.GetUserEffectiveBalancesAsync(user.Id, effectiveDate);

            return(HandleResult(result));
        }
Beispiel #7
0
        public ActionResult Balances(long userId)
        {
            if (!CurrentUser.IsAdmin)
            {
                throw new Exception("Unauthorized user access");
            }

            ViewBag.userId = userId;
            var user      = new EmployeeService().RetrieveEmployeeById(userId);
            var viewModel = new BalancesViewModel
            {
                UserDisplayName = user.DisplayName,
                UserId          = user.EmployeeId
            };

            return(View("Balances", viewModel));
        }
Beispiel #8
0
        public async Task <BalancesViewModel> GetUserEffectiveBalancesAsync(Guid userId, DateTime effectiveDate)
        {
            IEnumerable <Balance> balances = await _balanceRepository.GetByEffectiveDateAsync(userId, effectiveDate);

            List <BalanceViewModel> items = balances
                                            .Select(b => new BalanceViewModel(b))
                                            .OrderBy(i => i.Asset.Currency)
                                            .ThenBy(i => i.Asset.Name)
                                            .ToList();

            if (effectiveDate.Date == DateTime.UtcNow.Date)
            {
                await PopulateIsBankAccountFieldAsync(userId, items);
            }

            IEnumerable <BalanceTotalModel> totals = await _balancesTotalService.CalculateTotalsAsync(userId, balances, effectiveDate);

            BalancesViewModel result = new BalancesViewModel(items, items.Count, totals);

            return(result);
        }